diff --git a/pom.xml b/pom.xml
index ca9fefbba..bcdebf2f1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -156,8 +156,8 @@
1.8
- INFO
- OBFUSCATED
+ ALL
+ DETAILED
9
true
true
@@ -201,13 +201,13 @@
[%-5level] {%d{dd/MM/yyyy HH:mm:ss.SSS}} [%thread] %logger{35} - %msg%n
- ERROR
+ ALL
jdbc:postgresql://localhost:5432/sigmah
- sigmah
- sigmah
+ postgres
+ admin
@@ -885,7 +885,8 @@
org.jacoco
jacoco-maven-plugin
- 0.7.4.201502262128
+ 0.7.9
+
@@ -932,7 +933,7 @@
/
org.sigmah.Sigmah
- -Xmx1G -Xss256M -XX:PermSize=256M -Djava.io.tmpdir=${project.build.directory}
+ -Xmx1G -Xss128M -Djava.io.tmpdir=${project.build.directory}
@@ -1058,7 +1059,11 @@
-
+ jdbc:postgresql://localhost:5432/sigmah
+ postgres
+ admin
+ C:\\Users\\1\\Documents\\GitHub\\sigmah
+ C:\\Users\\1\\Documents\\GitHub\\sigmah\\archives
@@ -1222,4 +1227,4 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java
index 00f3847f9..0f49298d9 100644
--- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java
+++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarEventPresenter.java
@@ -21,7 +21,6 @@
* .
* #L%
*/
-
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
@@ -51,11 +50,17 @@
import org.sigmah.shared.dto.calendar.CalendarWrapper;
import org.sigmah.shared.dto.calendar.Event;
import org.sigmah.shared.dto.calendar.PersonalEventDTO;
-
import com.allen_sauer.gwt.log.client.Log;
import com.extjs.gxt.ui.client.event.ButtonEvent;
+import com.extjs.gxt.ui.client.event.DatePickerEvent;
+import com.extjs.gxt.ui.client.event.Events;
+import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionListener;
+import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.DateField;
+import com.extjs.gxt.ui.client.widget.form.FieldSet;
+import com.extjs.gxt.ui.client.widget.form.Radio;
+import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.Time;
@@ -63,345 +68,1684 @@
import com.google.inject.ImplementedBy;
import com.google.inject.Inject;
import com.google.inject.Singleton;
+import static java.lang.Integer.parseInt;
/**
* Calendar event presenter which manages the {@link CalendarEventView}.
- *
+ *
* @author Denis Colliot (dcolliot@ideia.fr)
*/
@Singleton
public class CalendarEventPresenter extends AbstractPagePresenter {
- /**
- * Description of the view managed by this presenter.
- */
- @ImplementedBy(CalendarEventView.class)
- public static interface View extends ViewInterface {
-
- FormPanel getForm();
-
- TextField getEventSummaryField();
-
- DateField getEventDateField();
-
- TimeField getEventStartTimeField();
-
- TimeField getEventEndTimeField();
-
- TextArea getEventDescriptionField();
-
- Button getSaveButton();
-
- Button getCancelButton();
-
- }
-
- /**
- * The edited calendar event, or {@code null} if creation.
- */
- private Event event;
-
- private CalendarWrapper calendarWrapper;
-
- /**
- * Presenters's initialization.
- *
- * @param view Presenter's view interface.
- * @param injector Injected client injector.
- */
- @Inject
- public CalendarEventPresenter(final View view, final Injector injector) {
- super(view, injector);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Page getPage() {
- return Page.CALENDAR_EVENT;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onBind() {
-
- // --
- // Cancel button listener.
- // --
- view.getCancelButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
- hideView();
- }
- });
-
- // --
- // Save button listener.
- // --
- view.getSaveButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
- onSaveAction();
- }
- });
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onPageRequest(final PageRequest request) {
-
- view.getForm().clearAll();
-
- // --
- // Reading inputs into request.
- // --
- event = request.getData(RequestParameter.DTO);
- final boolean creation = event == null;
-
- final List calendars = request.getData(RequestParameter.CONTENT);
-
- if (ClientUtils.isEmpty(calendars)) {
- hideView();
- throw new IllegalArgumentException("Provided calendars list is invalid.");
- }
-
- setPageTitle(creation ? I18N.CONSTANTS.calendarAddEvent() : I18N.CONSTANTS.calendarEditEvent());
-
- // --
- // Loading received calendars.
- // --
- for (final CalendarWrapper calendarWrapper : calendars) {
- if (calendarWrapper.getCalendar().isEditable()) {
- this.calendarWrapper = calendarWrapper;
- }
- }
-
- // --
- // Loading event on view (if edition).
- // --
- if (creation) {
- return;
- }
-
- this.calendarWrapper = new CalendarWrapper(event.getParent());
- view.getEventSummaryField().setValue(event.getSummary());
- view.getEventDateField().setValue(event.getKey());
-
- if (!isFullDayEvent(event)) {
-
- final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null;
- view.getEventStartTimeField().setValue(startTime);
-
- final Time endTime = event.getDtend() != null ? view.getEventEndTimeField().findModel(event.getDtend()) : null;
- view.getEventEndTimeField().setValue(endTime);
-
- }
-
- view.getEventDescriptionField().setValue(event.getDescription());
- }
-
- // ---------------------------------------------------------------------------------------------------------------
- //
- // UTILITY METHODS.
- //
- // ---------------------------------------------------------------------------------------------------------------
- /**
- * Method executed on save button action.
- */
- @SuppressWarnings("deprecation")
- private void onSaveAction() {
-
- if (!view.getForm().isValid()) {
- return;
- }
-
- // --
- // Building properties map.
- // --
- final Map properties = new HashMap();
- properties.put(Event.CALENDAR_ID, calendarWrapper);
- properties.put(Event.SUMMARY, view.getEventSummaryField().getValue());
-
- final Date date = view.getEventDateField().getValue();
- properties.put(Event.DATE, date);
-
- final Date startDate = view.getEventStartTimeField().getDateValue();
- if (startDate != null) {
- startDate.setYear(date.getYear());
- startDate.setMonth(date.getMonth());
- startDate.setDate(date.getDate());
- properties.put(Event.START_TIME, startDate.getTime());
- } else {
- properties.put(Event.START_TIME, null);
- }
-
- final Date endDate = view.getEventEndTimeField().getDateValue();
- if (endDate != null) {
- endDate.setYear(date.getYear());
- endDate.setMonth(date.getMonth());
- endDate.setDate(date.getDate());
- properties.put(Event.END_TIME, endDate.getTime());
- } else {
- properties.put(Event.END_TIME, null);
- }
-
- properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue());
-
- if (event == null) {
- addPersonalEvent(properties);
-
- } else {
- editPersonalEvent(event, properties);
- }
- }
-
- /**
- * Creates a new "Personal" calendar event.
- *
- * @param properties Properties of the new event.
- */
- private void addPersonalEvent(final Map properties) {
-
- final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties);
-
- dispatch.execute(createEntity, new CommandResultHandler() {
-
- @Override
- public void onCommandFailure(final Throwable caught) {
- if (Log.isErrorEnabled()) {
- Log.error(I18N.CONSTANTS.calendarAddEventError(), caught);
- }
- N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError());
- }
-
- @Override
- public void onCommandSuccess(final CreateResult result) {
-
- // Creating events.
- final Event event = new Event();
- event.setIdentifier((Integer) result.getEntity().getId());
-
- updateEvent(event, properties);
- }
- }, view.getCancelButton(), view.getSaveButton());
- }
-
- /**
- * Edits the events.
- *
- * @param properties Properties of the new event.
- */
- private void editPersonalEvent(final Event event, final Map properties) {
-
- @SuppressWarnings("unchecked")
- final UpdateEntity updateEntity = new UpdateEntity(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), (Map) properties);
-
- dispatch.execute(updateEntity, new CommandResultHandler() {
-
- @Override
- public void onCommandFailure(final Throwable caught) {
- if (Log.isErrorEnabled()) {
- Log.error(I18N.CONSTANTS.calendarAddEventError(), caught);
- }
- N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError());
- }
-
- @Override
- public void onCommandSuccess(final VoidResult result) {
-
- final Calendar calendar = event.getParent();
-
- final List oldEventList =
- calendar.getEvents().get(event.getKey());
- oldEventList.remove(event);
-
- updateEvent(event, properties);
- }
- }, view.getCancelButton(), view.getSaveButton());
- }
-
- /**
- * Updates the given {@code event} with the given {@code properties}.
- *
- * @param event The event to update.
- * @param properties The properties.
- */
- @SuppressWarnings("deprecation")
- private void updateEvent(final Event event, final Map properties) {
-
- // --
- // Updates the event.
- // --
- event.setSummary((String) properties.get(Event.SUMMARY));
- event.setDescription((String) properties.get(Event.DESCRIPTION));
-
- final Date day = (Date) properties.get(Event.DATE);
- final Object startHourSerialized = properties.get(Event.START_TIME);
- final Object endHourSerialized = properties.get(Event.END_TIME);
-
- if (startHourSerialized != null) {
- final Date startHour = new Date((Long) startHourSerialized);
- event.setDtstart(startHour);
- if (endHourSerialized != null) {
- final Date endHour = new Date((Long) endHourSerialized);
- event.setDtend(endHour);
- } else {
- event.setDtend(null);
- }
-
- } else {
- event.setDtstart(new Date(day.getYear(), day.getMonth(), day.getDate()));
- event.setDtend(new Date(day.getYear(), day.getMonth(), day.getDate() + 1));
- }
-
- // Adding the new event to the calendar
- final CalendarWrapper wrapper = (CalendarWrapper) properties.get(Event.CALENDAR_ID);
- final Calendar calendar = wrapper.getCalendar();
-
- event.setParent(calendar);
-
- List events = calendar.getEvents().get(day);
- if (events == null) {
- events = new ArrayList();
- calendar.getEvents().put(day, events);
- }
- events.add(event);
-
- // --
- // Sends an update event on the event bus.
- // --
- eventBus.fireEvent(new UpdateEvent(UpdateEvent.CALENDAR_EVENT_UPDATE, event));
- // calendarWidget.refresh();
-
- // --
- // Hides the view.
- // --
- hideView();
- }
-
- /**
- * Returns if the given {@code event} is a full day event.
- *
- * @param event The event.
- * @return {@code true} if the given {@code event} is a full day event.
- */
- @SuppressWarnings("deprecation")
- private static boolean isFullDayEvent(final Event event) {
-
- if (event == null) {
- return false;
- }
-
- return event.getDtend() != null
- && (event.getDtstart().getDate() != event.getDtend().getDate() || event.getDtstart().getMonth() != event.getDtend().getMonth() || event.getDtstart()
- .getYear() != event.getDtend().getYear());
- }
-
+ private Event event;
+ private CalendarWrapper calendarWrapper;
+
+ /**
+ * Description of the view managed by this presenter.
+ */
+ @ImplementedBy(CalendarEventView.class)
+ public static interface View extends ViewInterface {
+
+ /**
+ *
+ * @return
+ */
+ FormPanel getForm();
+
+ /**
+ *
+ * @return
+ */
+ TextField getEventSummaryField();
+
+ /**
+ *
+ * @return
+ */
+ DateField getEventDateStartField();
+
+ /**
+ *
+ * @return
+ */
+ DateField getEventDateEndField();
+
+ /**
+ *
+ * @return
+ */
+ TimeField getEventStartTimeField();
+
+ /**
+ *
+ * @return
+ */
+ TimeField getEventEndTimeField();
+
+ /**
+ *
+ * @return
+ */
+ TextArea getEventDescriptionField();
+
+ /**
+ *
+ * @return
+ */
+ Button getSaveButton();
+
+ /**
+ *
+ * @return
+ */
+ Button getCancelButton();
+
+ /**
+ *
+ * @return
+ */
+ CheckBox getAllDayCheckbox();
+
+ /**
+ *
+ * @return
+ */
+ FieldSet getPanelYearly();
+
+ /**
+ *
+ * @return
+ */
+ FieldSet getPanelMonthly();
+
+ /**
+ *
+ * @return
+ */
+ FieldSet getPanelWeekly();
+
+ /**
+ *
+ * @return
+ */
+ FieldSet getPanelDaily();
+
+ /**
+ *
+ * @return
+ */
+ FieldSet getMonthlyRepSettings();
+
+ /**
+ *
+ * @return
+ */
+ FieldSet getYearlyRepSettings();
+
+ /**
+ *
+ * @return
+ */
+ Radio getOnceRepeatRB();
+
+ /**
+ *
+ * @return
+ */
+ Radio getDailyRepeatRB();
+
+ /**
+ *
+ * @return
+ */
+ Radio getWeeklyRepeatRB();
+
+ /**
+ *
+ * @return
+ */
+ Radio getMonthlyRepeatRB();
+
+ /**
+ *
+ * @return
+ */
+ Radio getYearlyRepeatRB();
+
+ /**
+ *
+ * @return
+ */
+ RadioGroup getYearlyVariantRG();
+
+ /**
+ *
+ * @return
+ */
+ RadioGroup getMontlyVariantRG();
+
+ /**
+ *
+ * @return
+ */
+ Radio getYearlySameDayOfWeekRB();
+
+ /**
+ *
+ * @return
+ */
+ Radio getYearlySameDateRB();
+
+ /**
+ *
+ * @return
+ */
+ RadioGroup getRepeatEventPeriodRG();
+
+ /**
+ *
+ * @return
+ */
+ RadioGroup getRepeatMultiEventPeriodRG();
+
+ /**
+ *
+ * @return
+ */
+ Radio getRadioMonthlySameDate();
+
+ /**
+ *
+ * @return
+ */
+ Radio getRadioMonthlySameDayOfWeek();
+
+ /**
+ *
+ * @return
+ */
+ Radio getRadioRepetitionEndDate();
+
+ /**
+ *
+ * @return
+ */
+ Radio getRadioNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ Radio getDailyRadioRepetitionEndDate();
+
+ /**
+ *
+ * @return
+ */
+ Radio getDailyRadioNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ Radio getWeeklyRadioRepetitionEndDate();
+
+ /**
+ *
+ * @return
+ */
+ Radio getWeeklyRadioNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ Radio getYearlyRadioRepetitionEndDate();
+
+ /**
+ *
+ * @return
+ */
+ Radio getYearlyRadioNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ TextArea getNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ DateField getRepetitionEndDate();
+
+ /**
+ *
+ * @return
+ */
+ TextArea getWeeklyNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ DateField getWeeklyRepetitionEndDate();
+
+ /**
+ *
+ * @return
+ */
+ TextArea getYearlyNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ DateField getYearlyRepetitionEndDate();
+
+ /**
+ *
+ * @return
+ */
+ TextArea getDailyNumberOfRepetitions();
+
+ /**
+ *
+ * @return
+ */
+ DateField getDailyRepetitionEndDate();
+
+ // void setShowAddEventView(boolean showAddEventView);
+ }
+
+ /**
+ * The edited calendar event, or {@code null} if creation.
+ */
+ /**
+ * Presenters's initialization.
+ *
+ * @param view Presenter's view interface.
+ * @param injector Injected client injector.
+ */
+ @Inject
+ public CalendarEventPresenter(final View view, final Injector injector) {
+ super(view, injector);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Page getPage() {
+ return Page.CALENDAR_EVENT;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onBind() {
+
+ // --
+ // Cancel button listener.
+ // --
+ view.getCancelButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+ hideView();
+ }
+ });
+
+ // --
+ // Save button listener.
+ // --
+ view.getSaveButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+ onSaveAction();
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onPageRequest(final PageRequest request) {
+
+ view.getForm().clearAll();
+
+ // --
+ // Reading inputs into request.
+ // --
+ event = request.getData(RequestParameter.DTO);
+ final boolean creation = event == null;
+
+ final List calendars = request.getData(RequestParameter.CONTENT);
+
+ if (ClientUtils.isEmpty(calendars)) {
+ hideView();
+ throw new IllegalArgumentException("Provided calendars list is invalid.");
+ }
+
+ setPageTitle(creation ? I18N.CONSTANTS.calendarAddEvent() : I18N.CONSTANTS.calendarEditEvent());
+
+ // --
+ // Loading received calendars.
+ // --
+ for (final CalendarWrapper calendarWrapper : calendars) {
+ if (calendarWrapper.getCalendar().isEditable()) {
+ this.calendarWrapper = calendarWrapper;
+ }
+ }
+
+ // --
+ // Loading event on view (if edition).
+ // --
+ if (creation) {
+ prepareAddView();
+ } else {
+ prepareEditView();
+ }
+ }
+
+ /**
+ * Create Edit Calendar Event View
+ */
+ private void prepareEditView() {
+ this.calendarWrapper = new CalendarWrapper(event.getParent());
+
+ view.getForm().clearState();
+ view.getEventSummaryField().setValue(event.getSummary());
+ view.getEventDateStartField().setValue(event.getKey());
+ view.getEventDateEndField().setValue(event.getDtend());
+ view.getEventDateStartField().getDatePicker().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventDateEndField().getValue() == null) {
+ view.getEventDateEndField().setValue(view.getEventDateStartField().getValue());
+ }
+ }
+ });
+ view.getEventDateEndField().getDatePicker().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventDateStartField().getValue() == null) {
+ view.getEventDateStartField().setValue(view.getEventDateEndField().getValue());
+ }
+ }
+ });
+ /* view.getEventStartTimeField().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventEndTimeField().getValue() == null) {
+ view.getEventEndTimeField().setValue(view.getEventStartTimeField().getValue());
+ }
+ }
+ });
+ view.getEventEndTimeField().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventStartTimeField().getValue() == null) {
+ view.getEventStartTimeField().setValue(view.getEventEndTimeField().getValue());
+ }
+ }
+ });*/
+ if (view.getRepeatEventPeriodRG() != null) {
+ view.getRepeatEventPeriodRG().clear();
+ view.getRepeatEventPeriodRG().clearInvalid();
+ view.getRepeatEventPeriodRG().clearState();
+ view.getRepeatEventPeriodRG().setSelectionRequired(false);
+ view.getRepeatEventPeriodRG().hide();
+
+ view.getPanelMonthly().hide();
+ view.getMontlyVariantRG().hide();
+
+ view.getPanelYearly().hide();
+ view.getYearlyVariantRG().hide();
+
+ view.getPanelWeekly().hide();
+
+ view.getPanelDaily().hide();
+
+ view.getYearlyVariantRG().hide();
+ view.getMontlyVariantRG().hide();
+ view.getRepeatEventPeriodRG().hide();
+ view.getMonthlyRepeatRB().hide();
+ view.getYearlySameDateRB().hide();
+ view.getYearlySameDayOfWeekRB().hide();
+ view.getRadioMonthlySameDate().hide();
+ view.getRadioMonthlySameDayOfWeek().hide();
+
+ view.getRadioNumberOfRepetitions().setValue(true);
+ view.getNumberOfRepetitions().enable();
+ view.getRepetitionEndDate().disable();
+ view.getNumberOfRepetitions().setValue("1");
+ view.getRepetitionEndDate().setValue(new Date());
+
+ view.getYearlyRadioNumberOfRepetitions().setValue(true);
+ view.getYearlyNumberOfRepetitions().enable();
+ view.getYearlyRepetitionEndDate().disable();
+ view.getYearlyNumberOfRepetitions().setValue("1");
+ view.getYearlyRepetitionEndDate().setValue(new Date());
+
+ view.getWeeklyRadioNumberOfRepetitions().setValue(true);
+ view.getWeeklyNumberOfRepetitions().enable();
+ view.getWeeklyRepetitionEndDate().disable();
+ view.getWeeklyNumberOfRepetitions().setValue("1");
+ view.getWeeklyRepetitionEndDate().setValue(new Date());
+
+ view.getDailyRadioNumberOfRepetitions().setValue(true);
+ view.getDailyNumberOfRepetitions().enable();
+ view.getDailyRepetitionEndDate().disable();
+ view.getDailyNumberOfRepetitions().setValue("1");
+ view.getDailyRepetitionEndDate().setValue(new Date());
+ }
+ if (event.getEventType().contains("F")) {
+ view.getAllDayCheckbox().setValue(true);
+ view.getEventStartTimeField().hide();
+ view.getEventEndTimeField().hide();
+ } else {
+ view.getAllDayCheckbox().setValue(false);
+ view.getEventStartTimeField().show();
+ view.getEventEndTimeField().show();
+ }
+ if (!event.getEventType().contains("F")) {
+
+ final Time startTime = event.getDtstart() != null ? view.getEventStartTimeField().findModel(event.getDtstart()) : null;
+ view.getEventStartTimeField().setValue(startTime);
+
+ final Time endTime = event.getDtend() != null ? view.getEventEndTimeField().findModel(event.getDtend()) : null;
+ view.getEventEndTimeField().setValue(endTime);
+
+ }
+
+ view.getEventDescriptionField().setValue(event.getDescription());
+ }
+
+ /**
+ * Create Add Calendar Event View
+ */
+ private void prepareAddView() {
+ if (view.getRepeatEventPeriodRG() != null) {
+ view.getRepeatEventPeriodRG().enable();
+ view.getRepeatEventPeriodRG().show();
+ view.getOnceRepeatRB().setValue(true);
+ view.getPanelMonthly().hide();
+ view.getPanelYearly().hide();
+ view.getPanelWeekly().hide();
+ view.getPanelDaily().hide();
+ // view.getMonthlyRepSettings().hide();
+ // view.getYearlyRepSettings().hide();
+ }
+ view.getEventStartTimeField().show();
+ view.getEventEndTimeField().show();
+
+ view.getYearlyVariantRG().enable();
+ view.getMontlyVariantRG().enable();
+ view.getRepeatEventPeriodRG().enable();
+ view.getMonthlyRepeatRB().enable();
+ view.getYearlySameDateRB().enable();
+ view.getYearlySameDayOfWeekRB().enable();
+ view.getRadioMonthlySameDate().enable();
+ view.getRadioMonthlySameDayOfWeek().enable();
+
+ view.getRepeatMultiEventPeriodRG().enable();
+ view.getRadioNumberOfRepetitions().enable();
+ view.getRadioRepetitionEndDate().enable();
+ view.getNumberOfRepetitions().enable();
+ view.getRepetitionEndDate().enable();
+
+ view.getRepeatMultiEventPeriodRG().show();
+ view.getRadioNumberOfRepetitions().show();
+ view.getRadioRepetitionEndDate().show();
+ view.getNumberOfRepetitions().show();
+ view.getRepetitionEndDate().show();
+
+ view.getEventDateStartField().getDatePicker().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventDateEndField().getValue() == null) {
+ view.getEventDateEndField().setValue(view.getEventDateStartField().getValue());
+ }
+ }
+ });
+ view.getEventDateEndField().getDatePicker().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventDateStartField().getValue() == null) {
+ view.getEventDateStartField().setValue(view.getEventDateEndField().getValue());
+ }
+ }
+ });
+
+ /* view.getEventStartTimeField().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventEndTimeField().getValue() == null) {
+ view.getEventEndTimeField().setValue(view.getEventStartTimeField().getValue());
+ }
+ }
+ });
+ view.getEventEndTimeField().addListener(Events.Select, new Listener() {
+
+ @Override
+ public void handleEvent(DatePickerEvent be) {
+ if (view.getEventStartTimeField().getValue() == null) {
+ view.getEventStartTimeField().setValue(view.getEventEndTimeField().getValue());
+ }
+ }
+ }); */
+ view.getYearlyVariantRG().show();
+ view.getMontlyVariantRG().show();
+ view.getRepeatEventPeriodRG().show();
+ view.getMonthlyRepeatRB().show();
+ view.getYearlySameDateRB().show();
+ view.getYearlySameDayOfWeekRB().show();
+ view.getRadioMonthlySameDate().show();
+ view.getRadioMonthlySameDayOfWeek().show();
+ view.getEventDateEndField().show();
+ view.getAllDayCheckbox().setValue(true);
+ view.getEventStartTimeField().hide();
+ view.getEventEndTimeField().hide();
+
+ view.getRadioNumberOfRepetitions().setValue(true);
+ view.getNumberOfRepetitions().enable();
+ view.getRepetitionEndDate().disable();
+ view.getNumberOfRepetitions().setValue("1");
+ view.getRepetitionEndDate().setValue(new Date());
+
+ view.getYearlyRadioNumberOfRepetitions().setValue(true);
+ view.getYearlyNumberOfRepetitions().enable();
+ view.getYearlyRepetitionEndDate().disable();
+ view.getYearlyNumberOfRepetitions().setValue("1");
+ view.getYearlyRepetitionEndDate().setValue(new Date());
+
+ view.getWeeklyRadioNumberOfRepetitions().setValue(true);
+ view.getWeeklyNumberOfRepetitions().enable();
+ view.getWeeklyRepetitionEndDate().disable();
+ view.getWeeklyNumberOfRepetitions().setValue("1");
+ view.getWeeklyRepetitionEndDate().setValue(new Date());
+
+ view.getDailyRadioNumberOfRepetitions().setValue(true);
+ view.getDailyNumberOfRepetitions().enable();
+ view.getDailyRepetitionEndDate().disable();
+ view.getDailyNumberOfRepetitions().setValue("1");
+ view.getDailyRepetitionEndDate().setValue(new Date());
+ }
+
+ // ---------------------------------------------------------------------------------------------------------------
+ //
+ // UTILITY METHODS.
+ //
+ // ---------------------------------------------------------------------------------------------------------------
+ /**
+ * Method executed on save button action.
+ */
+ @SuppressWarnings("deprecation")
+ private void onSaveAction() {
+ // Window.alert("onSaveAction");
+ if (!view.getForm().isValid()) {
+ return;
+ }
+ // --
+ // Building properties map.
+ // --
+ final Map properties = new HashMap();
+ properties.put(Event.CALENDAR_ID, calendarWrapper);
+ properties.put(Event.SUMMARY, view.getEventSummaryField().getValue());
+
+ String eventSummary = view.getEventSummaryField().getValue();
+ String eventDescription = view.getEventDescriptionField().getValue();
+
+ final Date beginEventIntervalDate = view.getEventDateStartField().getValue();
+ properties.put(Event.DATE, beginEventIntervalDate);
+
+ Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null);
+ if (endEventIntervalDate == null) {
+ endEventIntervalDate = beginEventIntervalDate;
+ }
+ properties.put(Event.DATE_END, endEventIntervalDate);
+//Window.alert("Date start: " +beginEventIntervalDate.getYear()+"." +beginEventIntervalDate.getMonth()
+ // + "." + beginEventIntervalDate.getDate() + " | Date end: " +endEventIntervalDate.getYear()+"." +endEventIntervalDate.getMonth()
+ // + "." + endEventIntervalDate.getDate());//temp for checker
+ Boolean isFullDayEvent = view.getAllDayCheckbox().getValue();
+
+ // Window.alert("isAllDayEvent=" + isFullDayEvent);//temp for checker
+ Date startDateTime = createStartDateTimeProperty(isFullDayEvent, beginEventIntervalDate, properties);
+ Date endDateTime = createEndDateTimeProperty(isFullDayEvent, beginEventIntervalDate, properties);
+ int daysdiff = calculateEventDurationInDays(beginEventIntervalDate, endEventIntervalDate);
+ properties.put(Event.DESCRIPTION, view.getEventDescriptionField().getValue());
+
+ if (event == null) {
+ processAddEvent(endEventIntervalDate, beginEventIntervalDate, startDateTime, endDateTime, properties, eventSummary, eventDescription);
+ } else {
+
+ properties.put(Event.EVENT_TYPE, event.getEventType());
+ properties.put(Event.REFERENCE_ID, event.getReferenceId());
+
+ if (isFullDayEvent) {
+ // Window.alert("#3 isFullDayEvent event.getEventType() = " + event.getEventType());
+ if (event.getEventType() != null) {
+ if ("O".equals(event.getEventType())
+ || "OH".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, "OF");
+ } else if ("D".equals(event.getEventType())
+ || "DH".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, "DF");
+ } else if ("W".equals(event.getEventType())
+ || "WH".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, "WF");
+ } else if ("M".equals(event.getEventType())
+ || "MH".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, "MF");
+ } else if ("Y".equals(event.getEventType())
+ || "YH".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, "YF");
+ }
+ }
+ } else {
+// Window.alert("#4 not full day event.getEventType() = " + event.getEventType()
+// + " daysdiff=" + daysdiff);
+ if (event.getEventType() != null) {
+ //Window.alert("111 event.getEventType()=" + event.getEventType() + " daysdiff=" + daysdiff);
+ if ("OF".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, ("O" + (daysdiff > 1 ? "H" : "")));
+ } else if ("DF".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, ("D" + (daysdiff > 1 ? "H" : "")));
+ } else if ("WF".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, ("W" + (daysdiff > 1 ? "H" : "")));
+ } else if ("MF".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, ("M" + (daysdiff > 1 ? "H" : "")));
+ } else if ("YF".equals(event.getEventType())) {
+ properties.put(Event.EVENT_TYPE, ("Y" + (daysdiff > 1 ? "H" : "")));
+ }
+ }
+ }
+ editPersonalEvent(event, properties);
+ }
+
+ }
+
+ /**
+ * Add new calendar events processing.
+ *
+ * @param endEventIntervalDate the value of endEventIntervalDate
+ * @param beginEventIntervalDate the value of beginEventIntervalDate
+ * @param startDate the value of startDateTime
+ * @param endDate the value of endDateTime
+ * @param properties the value of properties
+ * @param eventSummary the value of eventSummary
+ * @param eventDescription the value of eventDescription
+ */
+ private void processAddEvent(Date endEventIntervalDate, final Date beginEventIntervalDate, Date startDate, Date endDate, final Map properties, String eventSummary, String eventDescription) {
+ long milisPerDay = 86400000; //24 * 60 * 60 * 1000)
+ long milisPerWeek = 7 * milisPerDay; //7 days * (24hour * 60minutes * 60seconds * 1000mili seconds)
+ long diffInMilis = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime();
+ Boolean isDailyRepeatEvent = view.getDailyRepeatRB() != null ? view.getDailyRepeatRB().getValue() : Boolean.FALSE;
+ Boolean isWeeklyRepeatEvent = view.getWeeklyRepeatRB().getValue();
+ Boolean isMonthlyRepeatEvent = view.getMonthlyRepeatRB().getValue();
+ Boolean isYearlyRepeatEvent = view.getYearlyRepeatRB().getValue();
+
+ Boolean isMonthlySameDayOfWeek = view.getRadioMonthlySameDayOfWeek().getValue();
+
+ Boolean isYearlySameDayOfWeek = view.getYearlySameDayOfWeekRB().getValue();
+ // Date endEventIntervalDate = (view.getEventDateEndField() != null ? view.getEventDateEndField().getValue() : null);
+ Date endEventIntervalDateRadio = view.getEventDateStartField().getValue();
+
+ if (isDailyRepeatEvent) {
+ long count = 0;
+ long lengthDailyEvent = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1;
+ if (view.getDailyRadioNumberOfRepetitions().getValue()) {
+ count = parseInt(view.getDailyNumberOfRepetitions().getValue());
+ // Window.alert("Count1 = "+count);
+ } else {
+ endEventIntervalDateRadio = view.getDailyRepetitionEndDate().getValue();
+ count = (((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1) / lengthDailyEvent;
+ }
+ diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime();
+ if (count <= 0) {
+ count = 1;
+ }
+ //Window.alert("Count2 = "+count);
+ processDailyEvents(count, lengthDailyEvent, milisPerDay, beginEventIntervalDate, endEventIntervalDateRadio, endEventIntervalDate, startDate, endDate, properties, eventSummary, eventDescription);
+ } else if (isWeeklyRepeatEvent) {
+ if (view.getWeeklyRadioNumberOfRepetitions().getValue()) {
+ endEventIntervalDateRadio.setDate(beginEventIntervalDate.getDate() + parseInt(view.getWeeklyNumberOfRepetitions().getValue()) * 7);
+ } else {
+ endEventIntervalDateRadio = view.getWeeklyRepetitionEndDate().getValue();
+ }
+ diffInMilis = endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime();
+ processWeeklyEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, startDate, endDate, properties, eventSummary, eventDescription);
+ } else if (isMonthlyRepeatEvent) {
+ if (view.getRadioNumberOfRepetitions().getValue()) {
+ endEventIntervalDateRadio.setMonth(beginEventIntervalDate.getMonth() + parseInt(view.getNumberOfRepetitions().getValue()));
+ } else {
+ endEventIntervalDateRadio = view.getRepetitionEndDate().getValue();
+ }
+ processMonthlyEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, properties, isMonthlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription);
+ } else if (isYearlyRepeatEvent) {
+ if (view.getYearlyRadioNumberOfRepetitions().getValue()) {
+ endEventIntervalDateRadio.setYear(beginEventIntervalDate.getYear() + parseInt(view.getYearlyNumberOfRepetitions().getValue()));
+ } else {
+ endEventIntervalDateRadio = view.getYearlyRepetitionEndDate().getValue();
+ }
+ processYearEvents(beginEventIntervalDate, endEventIntervalDate, endEventIntervalDateRadio, properties, isYearlySameDayOfWeek, startDate, endDate, eventSummary, eventDescription);
+ } else {
+ processOnceEvent(beginEventIntervalDate, diffInMilis, milisPerDay, startDate, endDate, properties, eventSummary, eventDescription);
+ }
+ }
+
+ /**
+ * Create Start event date time property
+ *
+ * @param isFullDayEvent the value of isFullDayEvent
+ * @param beginEventIntervalDate the value of beginEventIntervalDate
+ * @param properties the value of properties
+ */
+ private Date createStartDateTimeProperty(Boolean isFullDayEvent, final Date beginEventIntervalDate, final Map properties) {
+
+ Date startDate = null;
+ if (!isFullDayEvent) {
+ startDate = view.getEventStartTimeField().getDateValue();
+ }
+ if (startDate != null) {
+ startDate.setYear(beginEventIntervalDate.getYear());
+ startDate.setMonth(beginEventIntervalDate.getMonth());
+ startDate.setDate(beginEventIntervalDate.getDate());
+ properties.put(Event.START_TIME, startDate.getTime());
+ } else {
+ properties.put(Event.START_TIME, null);
+ }
+ return startDate;
+ }
+
+ /**
+ * Create End event date time property
+ *
+ * @param isFullDayEvent the value of isFullDayEvent
+ * @param beginEventIntervalDate the value of beginEventIntervalDate
+ * @param properties the value of properties
+ */
+ private Date createEndDateTimeProperty(Boolean isFullDayEvent, final Date beginEventIntervalDate, final Map properties) {
+
+ Date endDate = null;
+ if (!isFullDayEvent) {
+ endDate = view.getEventEndTimeField().getDateValue();
+ }
+ if (endDate != null) {
+ endDate.setYear(beginEventIntervalDate.getYear());
+ endDate.setMonth(beginEventIntervalDate.getMonth());
+ endDate.setDate(beginEventIntervalDate.getDate());
+ properties.put(Event.END_TIME, endDate.getTime());
+ } else {
+ properties.put(Event.END_TIME, null);
+ }
+ return endDate;
+ }
+
+ private void processOnceEvent(final Date beginEventIntervalDate1, long diffInMilis, long milisPerDay, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) {
+ long daysDiff = diffInMilis / milisPerDay + 1;
+ long beginEventIntervalDate = beginEventIntervalDate1.getTime();
+ properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));
+ properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));
+ // Window.alert("DaysDiff = "+daysDiff);
+ if (view.getAllDayCheckbox().getValue()) {
+ properties.put(Event.EVENT_TYPE, "OF");
+ } else {
+ properties.put(Event.EVENT_TYPE, ("O" + (daysDiff > 1 ? "H" : "")));
+ }
+ if (daysDiff == 1) {
+ addPersonalEvent(properties);
+ } else {
+ properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Once event)");
+ properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Once event)");
+// properties.put(Event.EVENT_TYPE, "O");
+// if (view.getAllDayCheckbox().getValue()) {
+// properties.put(Event.EVENT_TYPE, "OF");
+// }
+ addPersonalEventOnce(properties, daysDiff, beginEventIntervalDate, milisPerDay, startDate, endDate, eventSummary, eventDescription);
+ }
+ }
+
+ private void addPersonalEventOnce(final Map properties, final long daysInterval, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) {
+
+ final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties);
+
+ dispatch.execute(createEntity, new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ processAddEventError(caught);
+ }
+
+ @Override
+ public void onCommandSuccess(final CreateResult result) {
+
+ // Creating events.
+ final Event event = new Event();
+ event.setIdentifier((Integer) result.getEntity().getId());
+ properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId());
+ updateEvent(event, properties);
+ // addOnceSeriesEvent((Integer) result.getEntity().getId(), daysInterval, calBeginNextEventDateLong, milisPerDay, startDateTime, endDateTime, eventSummary, eventDescription);
+ }
+ }, view.getCancelButton(), view.getSaveButton());
+ }
+
+ /**
+ * Add new Daily calendar events processing.
+ *
+ * @param diffInMilis the value of diffInMilis
+ * @param milisPerDay the value of milisPerDay
+ * @param beginEventIntervalDate the value of beginEventIntervalDate
+ * @param startDate the value of startDateTime
+ * @param endDate the value of endDateTime
+ * @param properties the value of properties
+ * @param eventSummary the value of eventSummary
+ * @param eventDescription the value of eventDescription
+ */
+ private void processDailyEvents(long count, long lengthDailyEvent, long milisPerDay, final Date beginEventIntervalDate, final Date endEventIntervalDateRadio, final Date endEventIntervalDate, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) {
+ long calBeginNextEventDateLong = beginEventIntervalDate.getTime();
+ //Date calBeginNextEventDate = beginEventIntervalDate;
+ long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1;
+
+ properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Daily event 1 of " + count + ")");
+ properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Daily event 1 of " + count + ")");
+ if (view.getAllDayCheckbox().getValue()) {
+ properties.put(Event.EVENT_TYPE, "DF");
+ } else {
+ properties.put(Event.EVENT_TYPE, ("D" + (daysInterval > 1 ? "H" : "")));
+ }
+ properties.put(Event.DATE_END, new Date(calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1)));
+ addPersonalEventDaily(properties, count, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription);
+
+ }
+
+ private void addPersonalEventDaily(final Map properties, final long daysInterval, final long lengthDailyEvent, final long calBeginNextEventDateLong, final long milisPerDay, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) {
+
+ final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties);
+
+ dispatch.execute(createEntity, new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ processAddEventError(caught);
+ }
+
+ @Override
+ public void onCommandSuccess(final CreateResult result) {
+
+ // Creating events.
+ final Event event = new Event();
+ event.setIdentifier((Integer) result.getEntity().getId());
+ properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId());
+ updateEvent(event, properties);
+ addDailySeriesEvent((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDate, endDate, eventSummary, eventDescription);
+ // if (view.getAllDayCheckbox().getValue() == false) {
+ // addDailySeriesEventNew((Integer) result.getEntity().getId(), daysInterval, lengthDailyEvent, calBeginNextEventDateLong, milisPerDay, startDateTime, endDateTime, eventSummary, eventDescription);
+ // }
+ }
+ }, view.getCancelButton(), view.getSaveButton());
+ }
+
+ private void processAddEventError(final Throwable caught) {
+ if (Log.isErrorEnabled()) {
+ Log.error(I18N.CONSTANTS.calendarAddEventError(), caught);
+ }
+ N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarAddEventError());
+ }
+
+ private void addDailySeriesEvent(Integer ids, long daysInterval, long lengthDailyEvent, long calBeginNextEventDateLong1, long milisPerDay, final Date startDate, final Date endDate, String eventSummary, String eventDescription) {
+ //Date calBeginNextEventDate;
+ long calBeginNextEventDateLong = calBeginNextEventDateLong1;
+ for (int i = 1; i < daysInterval; i++) {
+
+ calBeginNextEventDateLong += (milisPerDay * lengthDailyEvent);
+ long calEndNextEventDateLong = calBeginNextEventDateLong + milisPerDay * (lengthDailyEvent - 1);
+ //calBeginNextEventDate = new Date(calBeginNextEventDateLong);
+
+ Map dailyProperties = new HashMap();
+ dailyProperties.put(Event.CALENDAR_ID, calendarWrapper);
+ dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue());
+
+ dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong));
+ if (view.getAllDayCheckbox().getValue()) {
+ dailyProperties.put(Event.EVENT_TYPE, "DF");
+ } else {
+ dailyProperties.put(Event.EVENT_TYPE, ("D" + (daysInterval > 1 ? "H" : "")));
+ }
+ dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong));
+ setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties);
+
+ String newSummary = eventSummary;
+ String newDescription = eventDescription;
+// newSummary += " (Daily event " + (i + 1) + " of " + daysInterval + ")";
+// newDescription += " (Daily event " + (i + 1) + " of " + daysInterval + ")";
+ dailyProperties.put(Event.SUMMARY, newSummary);
+ dailyProperties.put(Event.DESCRIPTION, newDescription);
+ dailyProperties.put(Event.REFERENCE_ID, ids);
+
+ addPersonalEvent(dailyProperties);
+ }
+ }
+
+ /**
+ * Add new Weekly calendar events processing.
+ *
+ * @param diffInMilis the value of diffInMilis
+ * @param milisPerWeek the value of milisPerWeek
+ * @param beginEventIntervalDate the value of beginEventIntervalDate
+ * @param startDate the value of startDateTime
+ * @param endDate the value of endDateTime
+ * @param properties the value of properties
+ * @param eventSummary the value of eventSummary
+ * @param eventDescription the value of eventDescription
+ */
+ private void processWeeklyEvents(final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Date startDate, final Date endDate, final Map properties, String eventSummary, String eventDescription) {
+ // Window.alert("processWeeklyEvents");
+ long milisPerDay = 86400000;
+ long weekDiff = ((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) / (milisPerDay * 7));
+ int weeksInterval = (int) weekDiff;
+ if ((((endEventIntervalDateRadio.getTime() - beginEventIntervalDate.getTime() + milisPerDay) % (milisPerDay * 7)) >= ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime() + milisPerDay)))
+ && (view.getWeeklyRadioNumberOfRepetitions().getValue())) {
+ weeksInterval++;
+ }
+ if (weeksInterval <= 0) {
+ weeksInterval = 1;
+ }
+ if (endEventIntervalDate.getTime() - beginEventIntervalDate.getTime() == 0) {
+ weeksInterval--;
+ }
+
+ long calBeginNextEventDateLong = beginEventIntervalDate.getTime();
+ long calEndNextEventDateLong = endEventIntervalDate.getTime();
+ long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1;
+
+ properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));
+ properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Weekly event 1 of " + weeksInterval + ")");
+// Window.alert("#5 processWeeklyEvents event.getEventType() = " + (event!=null?event.getEventType():"NULL")
+// + " daysInterval=" + daysInterval);
+ if (view.getAllDayCheckbox().getValue()) {
+ properties.put(Event.EVENT_TYPE, "WF");
+ } else {
+ //Window.alert("W +daysInterval" + daysInterval);
+ properties.put(Event.EVENT_TYPE, ("W" + (daysInterval > 1 ? "H" : "")));
+ }
+ addPersonalEventWeekly(properties, weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, daysInterval, startDate, endDate, eventSummary, eventDescription);
+
+ }
+
+ private void addPersonalEventWeekly(final Map properties, final int weeksInterval, final long calBeginNextEventDateLong, final long calEndNextEventDateLong, final long daysInterval, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription) {
+
+ final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties);
+
+ dispatch.execute(createEntity, new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ processAddEventError(caught);
+ }
+
+ @Override
+ public void onCommandSuccess(final CreateResult result) {
+
+ // Creating events.
+ final Event event = new Event();
+ event.setIdentifier((Integer) result.getEntity().getId());
+ updateEvent(event, properties);
+ properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId());
+ long milisPerDay = 86400000;
+ addDailySeriesEventNew2((Integer) properties.get(Event.REFERENCE_ID), weeksInterval, calBeginNextEventDateLong, calEndNextEventDateLong, milisPerDay * 7, startDate, endDate, eventSummary, eventDescription);
+ }
+ }, view.getCancelButton(), view.getSaveButton());
+ }
+
+ private void addDailySeriesEventNew2(Integer ids, int daysInterval, long calBeginNextEventDateLong, long calEndNextEventDateLong, long milisPerWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) {
+ long milisPerDay = 86400000; //24 * 60 * 60 * 1000)
+
+ for (int i = 1; i < daysInterval; i++) {
+
+ calBeginNextEventDateLong += milisPerWeek;
+ calEndNextEventDateLong += milisPerWeek;
+
+ long daysLength = ((calEndNextEventDateLong - calBeginNextEventDateLong) / milisPerDay) + 1;
+
+ Map dailyProperties = new HashMap();
+ dailyProperties.put(Event.CALENDAR_ID, calendarWrapper);
+ dailyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue());
+
+ dailyProperties.put(Event.DATE, new Date(calBeginNextEventDateLong));
+
+ dailyProperties.put(Event.DATE_END, new Date(calEndNextEventDateLong));
+
+ setFullDayEvent(startDate, endDate, new Date(calBeginNextEventDateLong), dailyProperties);
+
+ String newSummary = eventSummary;
+ String newDescription = eventDescription;
+ // newDescription += " (Weekly event " + (i + 1) + " of " + daysInterval + ")";
+ dailyProperties.put(Event.SUMMARY, newSummary);
+ dailyProperties.put(Event.DESCRIPTION, newDescription);
+ if (view.getAllDayCheckbox().getValue()) {
+ dailyProperties.put(Event.EVENT_TYPE, "WF");
+ } else {
+ //Window.alert("W2 +daysLength" + daysLength);
+ dailyProperties.put(Event.EVENT_TYPE, ("W" + (daysLength > 1 ? "H" : "")));
+ }
+ dailyProperties.put(Event.REFERENCE_ID, ids);
+
+ addPersonalEvent(dailyProperties);
+ }
+ }
+
+ /**
+ * Set date and time values for Full day events.
+ *
+ * @param startDate the value of startDateTime
+ * @param endDate the value of endDateTime
+ * @param calBeginNextEventDate the value of calBeginNextEventDate
+ * @param thePeriodProperties the value of thePeriodProperties
+ */
+ private void setFullDayEvent(final Date startDate, final Date endDate, Date calBeginNextEventDate, Map thePeriodProperties) {
+ if (startDate != null) {
+ calBeginNextEventDate.setHours(startDate.getHours());
+ calBeginNextEventDate.setMinutes(startDate.getMinutes());
+ thePeriodProperties.put(Event.START_TIME, calBeginNextEventDate.getTime());
+ } else {
+ thePeriodProperties.put(Event.START_TIME, null);
+ }
+
+ if (endDate != null) {
+ Date endD = calBeginNextEventDate;
+ endD.setHours(endDate.getHours());
+ endD.setMinutes(endDate.getMinutes());
+ thePeriodProperties.put(Event.END_TIME, endD.getTime());
+ } else {
+ thePeriodProperties.put(Event.END_TIME, null);
+ }
+ }
+
+ /**
+ * Add new Monthly calendar events processing.
+ *
+ * @param beginEventIntervalDate the value of beginEventIntervalDate
+ * @param endEventIntervalDate the value of endEventIntervalDate
+ * @param properties the value of properties
+ * @param isMonthlySameDayOfWeek the value of isMonthlySameDayOfWeek
+ * @param startDate the value of startDateTime
+ * @param endDate the value of endDateTime
+ * @param eventSummary the value of eventSummary
+ * @param eventDescription the value of eventDescription
+ */
+ private void processMonthlyEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isMonthlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) {
+ long milisPerDay = 86400000; //24 * 60 * 60 * 1000)
+ long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1;
+
+ if (view.getAllDayCheckbox().getValue()) {
+ properties.put(Event.EVENT_TYPE, "MF");
+ } else {
+ //Window.alert("M +daysInterval" + daysInterval);
+ properties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : "")));
+ }
+ properties.put(Event.DATE_END, endEventIntervalDate);
+ Date endEventIntervalDate1 = endEventIntervalDate;
+ long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime();
+ endEventIntervalDate = endEventIntervalDateRadio;
+ int yearStart = beginEventIntervalDate.getYear();
+ int yearEnd = endEventIntervalDate.getYear();
+ int yearInterval = yearEnd - yearStart;
+
+ int monthStart = beginEventIntervalDate.getMonth();//0 Jan 11 Dec
+ int monthEnd = endEventIntervalDate.getMonth();
+ int monthInterval = 0;
+ if (yearInterval > 0) {
+ monthInterval = (yearInterval - 1) * 12 + (12 - monthStart) + (monthEnd + 1);
+ } else {
+ monthInterval = monthEnd - monthStart + 1;
+ }
+ if (view.getRadioNumberOfRepetitions().getValue()) {
+ monthInterval--;
+ }
+ if (monthInterval <= 0) {
+ monthInterval = 1;
+ }
+ properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Monthly event 1 of " + monthInterval + ")");
+ properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Monthly event 1 of " + monthInterval + ")");
+ addPersonalEventMonthly(endEventIntervalDate1, properties, monthInterval, beginEventIntervalDate, milisDiff, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek);
+
+ }
+
+ private void addPersonalEventMonthly(final Date endEventIntervalDate, final Map properties, final int monthInterval, final Date beginEventIntervalDate, final long milisDiff, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isMonthlySameDayOfWeek) {
+ final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties);
+
+ dispatch.execute(createEntity, new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ processAddEventError(caught);
+ }
+
+ @Override
+ public void onCommandSuccess(final CreateResult result) {
+
+ // Creating events.
+ final Event event = new Event();
+ event.setIdentifier((Integer) result.getEntity().getId());
+ updateEvent(event, properties);
+ properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId());
+// long milisPerDay = 86400000;
+// long daysInterval = milisDiff / milisPerDay + 1;
+ addMonthlySeriesEvent(endEventIntervalDate, (String) result.getEntity().getId(), monthInterval, beginEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isMonthlySameDayOfWeek);
+ }
+ }, view.getCancelButton(), view.getSaveButton());
+ }
+
+ private void addMonthlySeriesEvent(Date endEventIntervalDate, String ids, int monthInterval, Date beginEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isMonthlySameDayOfWeek) {
+ Date calBeginNextEventDate = beginEventIntervalDate;
+ long diff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime();
+ long milisPerDay = 86400000; //24 * 60 * 60 * 1000)
+ long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1;
+
+ for (int i = 1; i < monthInterval; i++) {
+ calBeginNextEventDate = getMonthlySameDayOfWeek2(beginEventIntervalDate, calBeginNextEventDate, i, isMonthlySameDayOfWeek);
+
+ Map monthlyProperties = new HashMap();
+ monthlyProperties.put(Event.CALENDAR_ID, calendarWrapper);
+ monthlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue());
+
+ monthlyProperties.put(Event.DATE, calBeginNextEventDate);
+
+ monthlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + diff));
+ if (view.getAllDayCheckbox().getValue()) {
+ monthlyProperties.put(Event.EVENT_TYPE, "MF");
+ } else {
+ //Window.alert("M2 +daysInterval" + daysInterval);
+ monthlyProperties.put(Event.EVENT_TYPE, ("M" + (daysInterval > 1 ? "H" : "")));
+ }
+
+ setFullDayEvent(startDate, endDate, calBeginNextEventDate, monthlyProperties);
+
+ String newSummary = eventSummary;
+ String newDescription = eventDescription;
+ // newSummary += " (Monthly event " + (i + 1) + " of " + monthInterval + ")";
+ // newDescription += " (Monthly " + (isMonthlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + monthInterval + ")";
+ monthlyProperties.put(Event.SUMMARY, newSummary);
+ monthlyProperties.put(Event.DESCRIPTION, newDescription);
+
+ monthlyProperties.put(Event.REFERENCE_ID, ids);
+ addPersonalEvent(monthlyProperties);
+ }
+ }
+
+ /**
+ * Add new Yearly calendar events processing.
+ *
+ * @param beginEventIntervalDate the value of beginEventIntervalDate
+ * @param endEventIntervalDate the value of endEventIntervalDate
+ * @param properties the value of properties
+ * @param isYearlySameDayOfWeek the value of isYearlySameDayOfWeek
+ * @param startDate the value of startDateTime
+ * @param endDate the value of endDateTime
+ * @param eventSummary the value of eventSummary
+ * @param eventDescription the value of eventDescription
+ */
+ private void processYearEvents(final Date beginEventIntervalDate, Date endEventIntervalDate, final Date endEventIntervalDateRadio, final Map properties, Boolean isYearlySameDayOfWeek, final Date startDate, final Date endDate, String eventSummary, String eventDescription) {
+
+ properties.put(Event.DATE_END, endEventIntervalDate);
+ long milisDiff = endEventIntervalDate.getTime() - beginEventIntervalDate.getTime();
+ long milisPerDay = 86400000; //24 * 60 * 60 * 1000)
+ long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1;
+
+ endEventIntervalDate = endEventIntervalDateRadio;
+ int yearStart = beginEventIntervalDate.getYear();
+ int yearEnd = endEventIntervalDate.getYear();
+ int yearInterval = yearEnd - yearStart + 1;
+ if (view.getYearlyRadioNumberOfRepetitions().getValue()) {
+ yearInterval--;
+ }
+ if (yearInterval <= 0) {
+ yearInterval = 1;
+ }
+
+ if (view.getAllDayCheckbox().getValue()) {
+ properties.put(Event.EVENT_TYPE, "YF");
+ } else {
+ //Window.alert("Y +daysInterval" + daysInterval);
+ properties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : "")));
+ }
+ properties.put(Event.SUMMARY, (String) properties.get(Event.SUMMARY));// + " (Yearly event 1 of " + yearInterval + ")");
+ properties.put(Event.DESCRIPTION, (String) properties.get(Event.DESCRIPTION));// + " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event 1 of " + yearInterval + ")");
+
+ addPersonalEventYearly(milisDiff, properties, yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek);
+
+ }
+
+ private void addPersonalEventYearly(final long milisDiff, final Map properties, final int yearInterval, final Date beginEventIntervalDate, final Date endEventIntervalDate, final Date startDate, final Date endDate, final String eventSummary, final String eventDescription, final boolean isYearlySameDayOfWeek) {
+
+ final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties);
+
+ dispatch.execute(createEntity, new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ processAddEventError(caught);
+ }
+
+ @Override
+ public void onCommandSuccess(final CreateResult result) {
+
+ final Event event = new Event();
+ event.setIdentifier((Integer) result.getEntity().getId());
+ properties.put(Event.REFERENCE_ID, (Integer) result.getEntity().getId());
+ updateEvent(event, properties);
+ long milisPerDay = 86400000;
+ long daysInterval = milisDiff / milisPerDay + 1;
+
+ addYearlySeriesEvent(milisDiff, (String) result.getEntity().getId(), yearInterval, beginEventIntervalDate, endEventIntervalDate, startDate, endDate, eventSummary, eventDescription, isYearlySameDayOfWeek);
+ }
+ }, view.getCancelButton(), view.getSaveButton());
+ }
+
+ private void addYearlySeriesEvent(final long milisDiff, String ids, int yearInterval, Date beginEventIntervalDate, Date endEventIntervalDate, final Date startDate, final Date endDate, String eventSummary, String eventDescription, final boolean isYearlySameDayOfWeek) {
+ long milisPerDay = 86400000; //24 * 60 * 60 * 1000)
+ long daysInterval = ((endEventIntervalDate.getTime() - beginEventIntervalDate.getTime()) / milisPerDay) + 1;
+
+ Date calBeginNextEventDate = beginEventIntervalDate;
+ for (int i = 1; i < yearInterval; i++) {
+ calBeginNextEventDate = getYearlySameDayOfWeek(beginEventIntervalDate, calBeginNextEventDate, i, isYearlySameDayOfWeek);
+
+ Map yearlyProperties = new HashMap();
+ yearlyProperties.put(Event.CALENDAR_ID, calendarWrapper);
+ yearlyProperties.put(Event.SUMMARY, view.getEventSummaryField().getValue());
+
+ yearlyProperties.put(Event.DATE, calBeginNextEventDate);
+
+ if (view.getAllDayCheckbox().getValue()) {
+ yearlyProperties.put(Event.EVENT_TYPE, "YF");
+ } else {
+ //Window.alert("Y2 +daysInterval" + daysInterval);
+ yearlyProperties.put(Event.EVENT_TYPE, ("Y" + (daysInterval > 1 ? "H" : "")));
+ }
+
+ yearlyProperties.put(Event.DATE_END, new Date(calBeginNextEventDate.getTime() + milisDiff));
+
+ setFullDayEvent(startDate, endDate, calBeginNextEventDate, yearlyProperties);
+
+ String newSummary = eventSummary;
+ String newDescription = eventDescription;
+ // newSummary += " (Yearly event " + (i + 1) + " of " + yearInterval + ")";
+ // newDescription += " (Yearly " + (isYearlySameDayOfWeek ? "same Day of a week " : "same Date ") + "event " + (i + 1) + " of " + yearInterval + ")";
+ yearlyProperties.put(Event.SUMMARY, newSummary);
+ yearlyProperties.put(Event.DESCRIPTION, newDescription);
+
+ yearlyProperties.put(Event.REFERENCE_ID, ids);
+ addPersonalEvent(yearlyProperties);
+ }
+ }
+
+ /**
+ * Creates a new "Personal" calendar event.
+ *
+ * @param properties Properties of the new event.
+ */
+ private void addPersonalEvent(final Map properties) {
+
+ final CreateEntity createEntity = new CreateEntity(PersonalEventDTO.ENTITY_NAME, properties);
+
+ dispatch.execute(createEntity, new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ processAddEventError(caught);
+ }
+
+ @Override
+ public void onCommandSuccess(final CreateResult result) {
+
+ // Creating events.
+ final Event event = new Event();
+ event.setIdentifier((Integer) result.getEntity().getId());
+ updateEvent(event, properties);
+ }
+ }, view.getCancelButton(), view.getSaveButton());
+ }
+
+ /**
+ * Edits the events.
+ *
+ * @param properties Properties of the new event.
+ */
+ private void editPersonalEvent(final Event event, final Map properties) {
+
+ @SuppressWarnings("unchecked")
+ final UpdateEntity updateEntity = new UpdateEntity(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), (Map) properties);
+
+ dispatch.execute(updateEntity, new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ processAddEventError(caught);
+ }
+
+ @Override
+ public void onCommandSuccess(final VoidResult result) {
+
+ final Calendar calendar = event.getParent();
+
+ final List oldEventList = calendar.getEvents().get(event.getKey());
+ if (oldEventList != null && oldEventList.contains(event)) {
+ oldEventList.remove(event);
+ }
+ final List oldFullDayEventList = calendar.getFullDayEvents().get(event.getKey());
+ if (oldFullDayEventList != null && oldFullDayEventList.contains(event)) {
+ oldFullDayEventList.remove(event);
+ }
+ final List oldHourMultidayEventList = calendar.getHourMultiDayEvents().get(event.getKey());
+ if (oldHourMultidayEventList != null && oldHourMultidayEventList.contains(event)) {
+ oldHourMultidayEventList.remove(event);
+ }
+ updateEvent(event, properties);
+ }
+ }, view.getCancelButton(), view.getSaveButton());
+ }
+
+ /**
+ * Updates the given {@code event} with the given {@code properties}.
+ *
+ * @param event The event to update.
+ * @param properties The properties.
+ */
+ @SuppressWarnings("deprecation")
+ private void updateEvent(final Event event, final Map properties) {
+
+ // --
+ // Updates the event.
+ // --
+ event.setSummary((String) properties.get(Event.SUMMARY));
+ event.setDescription((String) properties.get(Event.DESCRIPTION));
+ event.setEventType((String) properties.get(Event.EVENT_TYPE));
+
+ event.setReferenceId((Integer) properties.get(Event.REFERENCE_ID));
+
+ final Date day = (Date) properties.get(Event.DATE);
+ final Date dayEnd = (Date) properties.get(Event.DATE_END);
+ final Object startHourSerialized = properties.get(Event.START_TIME);
+ final Object endHourSerialized = properties.get(Event.END_TIME);
+
+ if (startHourSerialized != null) {
+ final Date startHour = new Date((Long) startHourSerialized);
+ event.setDtstart(startHour);
+ if (endHourSerialized != null) {
+ final Date endHour = new Date((Long) endHourSerialized + ((dayEnd.getTime() - day.getTime())));
+ //86400000
+ event.setDtend(endHour);
+ } else {
+ event.setDtend(null);
+ }
+
+ } else {
+ event.setDtstart(new Date(day.getYear(), day.getMonth(), day.getDate()));
+ event.setDtend(new Date(dayEnd.getYear(), dayEnd.getMonth(), dayEnd.getDate()));
+ }
+
+ // Adding the new event to the calendar
+ final CalendarWrapper wrapper = (CalendarWrapper) properties.get(Event.CALENDAR_ID);
+ final Calendar calendar = wrapper.getCalendar();
+
+ event.setParent(calendar);
+
+ if (calendar.getEvents() != null
+ && !event.getEventType().contains("F")
+ && !event.getEventType().contains("H")) {
+ List events = calendar.getEvents().get(day);
+ if (events == null) {
+ events = new ArrayList();
+ calendar.getEvents().put(day, events);
+ }
+ events.add(event);
+ }
+ if (calendar.getHourMultiDayEvents() != null
+ && event.getEventType().contains("H")) {
+ List hourMultiDayEvents = calendar.getHourMultiDayEvents().get(day);
+ if (hourMultiDayEvents == null) {
+ hourMultiDayEvents = new ArrayList();
+ calendar.getHourMultiDayEvents().put(day, hourMultiDayEvents);
+ }
+ hourMultiDayEvents.add(event);
+ }
+// if (calendar.getFullDayEvents() != null && (event.getEventType().contains("F")
+// && !event.getEventType().contains("H")
+// || (event.getDtstart().getHours() == event.getDtend().getHours()
+// && event.getDtstart().getMinutes() == event.getDtend().getMinutes()))) {
+ if (calendar.getFullDayEvents() != null
+ && event.getEventType().contains("F")) {
+ List fullDayEvents = calendar.getFullDayEvents().get(day);
+ if (fullDayEvents == null) {
+ fullDayEvents = new ArrayList();
+ calendar.getFullDayEvents().put(day, fullDayEvents);
+ }
+ fullDayEvents.add(event);
+ }
+ // --
+ // Sends an update event on the event bus.
+ // --
+ eventBus.fireEvent(new UpdateEvent(UpdateEvent.CALENDAR_EVENT_UPDATE, event));
+ // calendarWidget.refresh();
+
+ // --
+ // Hides the view.
+ // --
+ hideView();
+ }
+
+ /**
+ * Returns if the given {@code event} is a full day event.
+ *
+ * @param event The event.
+ * @return {@code true} if the given {@code event} is a full day event.
+ */
+ @SuppressWarnings("deprecation")
+ private static boolean isFullDayEvent(final Event event) {
+
+ if (event == null) {
+ return false;
+ }
+
+ return event.getDtend() != null
+ && (event.getDtstart().getDate() != event.getDtend().getDate() || event.getDtstart().getMonth() != event.getDtend().getMonth() || event.getDtstart()
+ .getYear() != event.getDtend().getYear());
+ }
+
+ /**
+ *
+ * @param firstDate
+ * @param nextDateOld
+ * @param numberMonths
+ * @return the java.util.Date
+ */
+ @SuppressWarnings({"deprecation", "empty-statement"})
+ public Date getMonthlySameDate(Date firstDate, Date nextDateOld, int numberMonths) {
+ Date nextDateNew = new Date();
+ Date newDate = new Date();
+ nextDateNew.setYear(nextDateOld.getYear());
+ nextDateNew.setMonth(nextDateOld.getMonth() + 1);
+ nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr)
+ newDate.setYear(nextDateOld.getYear());
+
+ int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth());
+
+ if (firstDate.getDate() <= daysInNextDate) {//if last day of the month
+ newDate.setMonth(0);
+ newDate.setDate(firstDate.getDate());
+ newDate.setMonth(nextDateOld.getMonth() + 1);
+
+ } else {
+ newDate.setDate(daysInNextDate);
+ newDate.setMonth(nextDateOld.getMonth() + 1);
+
+ }
+
+ return newDate;
+ }
+
+ /**
+ * Calculates same date or same day of week in next month.
+ *
+ * @param firstDate
+ * @param nextDateOld
+ * @param numberMonths
+ * @param isSameDayOfWeek if the value is true then will be calculated Date
+ * of the nearest same day of week
+ * @return next month date
+ */
+ public Date getMonthlySameDayOfWeek2(Date firstDate, Date nextDateOld, int numberMonths, boolean isSameDayOfWeek) {
+
+ Date nextDateNew = new Date();
+ Date newDate = new Date();
+ nextDateNew.setDate(1);// to prevent month slip past (f.e. 31 jan -> 3 march instead of 29 febr)
+ newDate.setDate(1);
+ nextDateNew.setYear(nextDateOld.getYear());
+ nextDateNew.setMonth(nextDateOld.getMonth() + 1);
+ newDate.setYear(nextDateOld.getYear());
+
+ int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth());
+
+ if (firstDate.getDate() <= daysInNextDate) {//if last day of the month
+ newDate.setMonth(0);
+ newDate.setDate(firstDate.getDate());
+ newDate.setMonth(nextDateOld.getMonth() + 1);
+
+ } else {
+ newDate.setDate(daysInNextDate);
+ newDate.setMonth(nextDateOld.getMonth() + 1);
+
+ }
+ if (isSameDayOfWeek) {
+ Date newDate2 = getSameWeekDay(firstDate, newDate); //getSameWeekDay22
+
+ newDate = newDate2;
+ }
+ return newDate;
+ }
+
+ /**
+ * Calculates same date or same day of week in next year.
+ *
+ * @param firstDate
+ * @param nextDateOld
+ * @param numberMonths
+ * @param isSameDayOfWeek if the value is true then will be calculated Date
+ * of the nearest same day of week
+ * @return
+ */
+ @SuppressWarnings({"deprecation"})
+ public Date getYearlySameDayOfWeek(Date firstDate, Date nextDateOld, int numberMonths, boolean isSameDayOfWeek) {
+
+ Date nextDateNew = new Date();
+ nextDateNew.setDate(1);
+ nextDateNew.setYear(nextDateOld.getYear());
+ nextDateNew.setMonth(nextDateOld.getMonth());
+ nextDateNew.setYear(nextDateOld.getYear() + 1);
+
+ int daysInNextDate = getDaysInMonth(nextDateNew.getYear(), nextDateNew.getMonth());
+
+ if (firstDate.getDate() >= daysInNextDate) {//if last day of the month
+
+ nextDateNew.setDate(daysInNextDate);
+
+ } else {
+
+ nextDateNew.setDate(firstDate.getDate());
+
+ }
+
+ if (isSameDayOfWeek) {
+
+ Date newDate = getSameWeekDay(firstDate, nextDateNew);//getSameWeekDay2
+
+ nextDateNew = newDate;
+ }
+
+ return nextDateNew;
+ }
+
+ /**
+ * Calculates same week day date(as in firstDate) for nextDate
+ *
+ * @param firstDate the value of firstDate
+ * @param nextDate the value of nextDate
+ */
+ private Date getSameWeekDay(Date firstDate, Date nextDate) {
+ //Calculate same day of week
+ int dayOfFirst = firstDate.getDay();
+ int dayOfCurrent = nextDate.getDay();
+ Date newDate = new Date();
+ Date curDate = nextDate;
+ int milSecInDay = 86400000; //24 * 60 * 60 * 1000
+ if (dayOfFirst > dayOfCurrent) {
+ newDate = new Date(curDate.getTime() + (dayOfFirst - dayOfCurrent) * milSecInDay);
+ if (newDate.getMonth() != curDate.getMonth()) { //>
+ newDate = new Date(curDate.getTime() - (7 - (dayOfFirst - dayOfCurrent)) * milSecInDay);
+ }
+
+ } else if (dayOfFirst < dayOfCurrent) {//<
+ newDate = new Date(curDate.getTime() - (dayOfCurrent - dayOfFirst) * milSecInDay);
+ if (newDate.getMonth() != curDate.getMonth()) {
+ newDate = new Date(curDate.getTime() + (7 - (dayOfCurrent - dayOfFirst)) * milSecInDay);
+ }
+ } else {
+ newDate = new Date(curDate.getTime());
+ }
+ return newDate;
+ }
+
+ /**
+ * Returns numver od days in the month of the year
+ *
+ * @param year the value of year
+ * @param month the value of month
+ * @return the int
+ */
+ private int getDaysInMonth(int year, int month) {
+ int daysInMonth = 31;
+
+ switch (month) {
+ case 3:
+ case 5:
+ case 8:
+ case 10:
+ return daysInMonth = 30;
+ case 1:
+ return daysInMonth = (isLeapYear(year)) ? 29 : 28;
+ default:
+ return daysInMonth;
+ }
+ }
+
+ /**
+ * Validate if the year is leap year.
+ *
+ * @param year the value of year
+ * @return the boolean
+ */
+ private boolean isLeapYear(int year) {
+ return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
+ }
+
+ private static int calculateEventDurationInDays(final Date startDateTime, Date endDateTime) {
+ long diff = endDateTime.getTime() - startDateTime.getTime();
+ long diffDays = diff / (24 * 60 * 60 * 1000) + 1;
+ int daysdiff = (int) diffDays;
+ return daysdiff;
+ }
}
diff --git a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java
index 93d828d98..19050eaff 100644
--- a/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java
+++ b/src/main/java/org/sigmah/client/ui/presenter/calendar/CalendarPresenter.java
@@ -21,8 +21,6 @@
* .
* #L%
*/
-
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -51,24 +49,20 @@
import org.sigmah.shared.dto.calendar.CalendarWrapper;
import org.sigmah.shared.dto.calendar.Event;
import org.sigmah.shared.dto.calendar.PersonalEventDTO;
-import org.sigmah.shared.dto.referential.GlobalPermissionEnum;
-import org.sigmah.shared.util.ProfileUtils;
-
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel;
-import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.inject.ImplementedBy;
import com.google.inject.Inject;
+import java.util.Date;
import org.sigmah.client.ui.presenter.reminder.ReminderType;
import org.sigmah.client.util.profiler.Profiler;
import org.sigmah.client.util.profiler.Scenario;
import org.sigmah.shared.dto.calendar.CalendarIdentifier;
import org.sigmah.shared.dto.calendar.PersonalCalendarIdentifier;
-import org.sigmah.shared.util.ProjectUtils;
/**
* Calendar widget presenter.
@@ -77,383 +71,483 @@
*/
public class CalendarPresenter extends AbstractPresenter {
- /**
- * Description of the view managed by this presenter.
- */
- @ImplementedBy(CalendarView.class)
- public static interface View extends ViewInterface {
+ /**
+ * Description of the view managed by this presenter.
+ */
+ @ImplementedBy(CalendarView.class)
+ public static interface View extends ViewInterface {
- void initializeCalendarWidget(final CalendarWidget calendarWidget);
+ void initializeCalendarWidget(final CalendarWidget calendarWidget);
- void setAddEventButtonEnabled(final boolean addEventButtonEnabled);
+ void setAddEventButtonEnabled(final boolean addEventButtonEnabled);
- AbstractStoreSelectionModel getCalendarsSelectionModel();
+ AbstractStoreSelectionModel getCalendarsSelectionModel();
- ListStore getCalendarsStore();
+ ListStore getCalendarsStore();
- Button getAddEventButton();
+ Button getAddEventButton();
- Button getTodayButton();
+ Button getTodayButton();
- Button getWeekButton();
+ Button getWeekButton();
- Button getMonthButton();
+ Button getMonthButton();
- Button getPreviousButton();
+ Button getPreviousButton();
- Button getNextButton();
+ Button getNextButton();
Button getReminderAddButton();
- Button getMonitoredPointsAddButton();
+ Button getMonitoredPointsAddButton();
- }
+ }
- /**
- * The calendar widget.
- */
- private CalendarWidget calendar;
+ /**
+ * The calendar widget.
+ */
+ private CalendarWidget calendar;
private Integer projectId;
+ // @Inject
+ // private PersonalEventDAO personalEventDAO;
+
+ /**
+ * Presenters's initialization.
+ *
+ * @param view Presenter's view interface.
+ * @param injector Injected client injector.
+ */
+ @Inject
+ protected CalendarPresenter(final View view, final Injector injector) {
+ super(view, injector);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onBind() {
+
+ // --
+ // Initialize calendar widget.
+ // --
+ calendar = new CalendarWidget(CalendarWidget.COLUMN_HEADERS, true, auth());
+ calendar.today(); // Reset the current date.
+ calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH);
+
+ view.initializeCalendarWidget(calendar);
+
+ view.setAddEventButtonEnabled(false);
+
+ // --
+ // Configuring calendar delegate.
+ // --
+ calendar.setDelegate(new CalendarWidget.Delegate() {
+
+ @Override
+ public void edit(final Event event, final CalendarWidget calendarWidget) {
+ eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.DTO, event).addData(RequestParameter.CONTENT, getCalendars()));
+ }
+
+ @Override
+ public void delete(final Event event, final CalendarWidget calendarWidget) {
+ final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier();
+ final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier
+ ? ((PersonalCalendarIdentifier) calendarIdentifier).getId() : null;
+ dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError());
+ }
+
+ @Override
+ public void onCommandSuccess(final VoidResult result) {
+
+ if (event.getEventType().contains("F")) {
+ final List oldFullDayEventList
+ = event.getParent().getFullDayEvents().get(event.getKey());
+ oldFullDayEventList.remove(event);
+ } else if (event.getEventType().contains("H")) {
+ final List oldHourMultidayEventList
+ = event.getParent().getHourMultiDayEvents().get(event.getKey());
+ oldHourMultidayEventList.remove(event);
+ } else {
+ final List oldEventList
+ = event.getParent().getEvents().get(event.getKey());
+ oldEventList.remove(event);
+ }
+ calendar.refresh();
+ }
+ });
+ }
+
+ public void deleteChildEvent(final Event next, Integer parentId, final Map> eventMap, final Date key) {
+ dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, next.getIdentifier(), parentId), new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError());
+ }
+
+ @Override
+ public void onCommandSuccess(final VoidResult result) {
+ eventMap.get(key).remove(next);
+ calendar.refresh();
+ }
+ });
+ }
+
+ public void deleteParentEvent(final Event next, Integer parentId, final Map> eventMap, final Date key, int mainId) {
+ dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, mainId, parentId), new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError());
+ }
+
+ @Override
+ public void onCommandSuccess(final VoidResult result) {
+ eventMap.get(key).remove(next);
+ calendar.refresh();
+ }
+ });
+ }
+
+ @Override
+ public void deleteChain(final Event event, final CalendarWidget calendarWidget) {
+ final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier();
+ final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier
+ ? ((PersonalCalendarIdentifier) calendarIdentifier).getId() : null;
+
+ final Map> eventMap = event.getParent().getEvents();
+ final Map> fullDayEventMap = event.getParent().getFullDayEvents();
+ final Map> hourMultiDayEventMap = event.getParent().getHourMultiDayEvents();
+
+ int eventId = event.getIdentifier();
+ int eventRefId = 0;
+ if (event.getReferenceId() != null) {
+ eventRefId = event.getReferenceId().intValue();
+ }
+ String typeStr = (String) event.getEventType();
+ if (typeStr != null) {
+ deleteEventFromEventMap(eventMap, eventRefId, parentId, eventId);
+ deleteEventFromEventMap(fullDayEventMap, eventRefId, parentId, eventId);
+ deleteEventFromEventMap(hourMultiDayEventMap, eventRefId, parentId, eventId);
+ } else {
+ dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, eventId, parentId), new CommandResultHandler() {
+
+ @Override
+ public void onCommandFailure(final Throwable caught) {
+ N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError());
+ }
+
+ @Override
+ public void onCommandSuccess(final VoidResult result) {
+
+ if (event.getEventType().contains("F")) {
+ final List oldFullDayEventList
+ = event.getParent().getFullDayEvents().get(event.getKey());
+ oldFullDayEventList.remove(event);
+ } else if (event.getEventType().contains("H")) {
+ final List oldHourMultidayEventList
+ = event.getParent().getHourMultiDayEvents().get(event.getKey());
+ oldHourMultidayEventList.remove(event);
+ } else {
+ final List oldEventList
+ = event.getParent().getEvents().get(event.getKey());
+ oldEventList.remove(event);
+ }
+ calendar.refresh();
+ }
+ });
+ }
+ }
+
+ private void deleteEventFromEventMap(final Map> theEventMap, int eventRefId, final Integer parentId, int eventId) {
+ for (final Date key : theEventMap.keySet()) {
+ for (final Event nextEvent : theEventMap.get(key)) {
+ if (eventRefId != 0) {
+// if (nextEvent.getReferenceId().intValue() == eventRefId) {
+// deleteChildEvent(nextEvent, parentId, theEventMap, key);
+// }
+ if ((nextEvent.getReferenceId() != null && (nextEvent.getReferenceId().intValue() == eventRefId))
+ || ((nextEvent.getReferenceId() == null) && (nextEvent.getIdentifier().intValue() == eventRefId))) {
+ deleteChildEvent(nextEvent, parentId, theEventMap, key);
+ }
+ } else {
+ if (nextEvent.getReferenceId() != null && (nextEvent.getReferenceId().intValue() == eventId)) {
+ deleteChildEvent(nextEvent, parentId, theEventMap, key);
+ } else if (nextEvent.getReferenceId() == null && nextEvent.getIdentifier().intValue() == eventId) {
+ deleteParentEvent(nextEvent, parentId, theEventMap, key, eventId);
+ }
+ }
+ }
+ }
+ }
+ });
+
+ // --
+ // Calendars selection change event.
+ // --
+ view.getCalendarsSelectionModel().addSelectionChangedListener(new SelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent se) {
+ final List wrappers = se.getSelection();
+ final ArrayList calendars = new ArrayList();
+ for (final CalendarWrapper wrapper : wrappers) {
+ calendars.add(wrapper.getCalendar());
+ }
+ calendar.setCalendars(calendars);
+ }
+ });
+
+ // --
+ // Add event button.
+ // --
+ view.getAddEventButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+
+ if (view.getCalendarsStore().getCount() == 0) {
+ N10N.warn(I18N.CONSTANTS.calendar_addEvent_noCalendar_ko());
+ return;
+ }
- /**
- * Presenters's initialization.
- *
- * @param view
- * Presenter's view interface.
- * @param injector
- * Injected client injector.
- */
- @Inject
- protected CalendarPresenter(final View view, final Injector injector) {
- super(view, injector);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onBind() {
-
- // --
- // Initialize calendar widget.
- // --
-
- calendar = new CalendarWidget(CalendarWidget.COLUMN_HEADERS, true, auth());
- calendar.today(); // Reset the current date.
- calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH);
-
- view.initializeCalendarWidget(calendar);
-
- view.setAddEventButtonEnabled(false);
-
- // --
- // Configuring calendar delegate.
- // --
-
- calendar.setDelegate(new CalendarWidget.Delegate() {
-
- @Override
- public void edit(final Event event, final CalendarWidget calendarWidget) {
- eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.DTO, event).addData(RequestParameter.CONTENT, getCalendars()));
- }
-
- @Override
- public void delete(final Event event, final CalendarWidget calendarWidget) {
- final CalendarIdentifier calendarIdentifier = event.getParent().getIdentifier();
- final Integer parentId = calendarIdentifier instanceof PersonalCalendarIdentifier ?
- ((PersonalCalendarIdentifier)calendarIdentifier).getId() : null;
-
- dispatch.execute(new Delete(PersonalEventDTO.ENTITY_NAME, event.getIdentifier(), parentId), new CommandResultHandler() {
-
- @Override
- public void onCommandFailure(final Throwable caught) {
- N10N.error(I18N.CONSTANTS.error(), I18N.CONSTANTS.calendarDeleteEventError());
- }
-
- @Override
- public void onCommandSuccess(final VoidResult result) {
-
- final List oldEventList =
- event.getParent().getEvents().get(event.getKey());
- oldEventList.remove(event);
- calendar.refresh();
- }
- });
- }
- });
-
- // --
- // Calendars selection change event.
- // --
-
- view.getCalendarsSelectionModel().addSelectionChangedListener(new SelectionChangedListener() {
-
- @Override
- public void selectionChanged(SelectionChangedEvent se) {
- final List wrappers = se.getSelection();
- final ArrayList calendars = new ArrayList();
- for (final CalendarWrapper wrapper : wrappers) {
- calendars.add(wrapper.getCalendar());
- }
- calendar.setCalendars(calendars);
- }
- });
-
- // --
- // Add event button.
- // --
-
- view.getAddEventButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
-
- if (view.getCalendarsStore().getCount() == 0) {
- N10N.warn(I18N.CONSTANTS.calendar_addEvent_noCalendar_ko());
- return;
- }
-
- eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.CONTENT, getCalendars()));
- }
- });
-
- // --
- // Today button.
- // --
-
- view.getTodayButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
- calendar.today();
- }
- });
-
- // --
- // Week button.
- // --
-
- view.getWeekButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
- calendar.setDisplayMode(CalendarWidget.DisplayMode.WEEK);
- }
- });
-
- // --
- // Month button.
- // --
-
- view.getMonthButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
- calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH);
- }
- });
-
- // --
- // Previous button.
- // --
-
- view.getPreviousButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
- calendar.previous();
- }
- });
-
- // --
- // Next button.
- // --
-
- view.getNextButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent ce) {
- calendar.next();
- }
- });
-
- // --
- // Reminders / Monitored Points add buttons handlers.
- // --
-
- view.getReminderAddButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent event) {
- eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.REMINDER).addParameter(RequestParameter.ID,
- projectId));
- }
- });
-
- view.getMonitoredPointsAddButton().addSelectionListener(new SelectionListener() {
-
- @Override
- public void componentSelected(final ButtonEvent event) {
- eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.MONITORED_POINT).addParameter(RequestParameter.ID,
- projectId));
- }
- });
+ eventBus.navigateRequest(Page.CALENDAR_EVENT.request().addData(RequestParameter.CONTENT, getCalendars()));
+ }
+ });
+
+ // --
+ // Today button.
+ // --
+ view.getTodayButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+ calendar.today();
+ }
+ });
+
+ // --
+ // Week button.
+ // --
+ view.getWeekButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+ calendar.setDisplayMode(CalendarWidget.DisplayMode.WEEK);
+ }
+ });
+
+ // --
+ // Month button.
+ // --
+ view.getMonthButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+ calendar.setDisplayMode(CalendarWidget.DisplayMode.MONTH);
+ }
+ });
+
+ // --
+ // Previous button.
+ // --
+ view.getPreviousButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+ calendar.previous();
+ }
+ });
+
+ // --
+ // Next button.
+ // --
+ view.getNextButton().addSelectionListener(new SelectionListener() {
- // --
- // Update event handler.
- // --
+ @Override
+ public void componentSelected(final ButtonEvent ce) {
+ calendar.next();
+ }
+ });
+
+ // --
+ // Reminders / Monitored Points add buttons handlers.
+ // --
+ view.getReminderAddButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent event) {
+ eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.REMINDER).addParameter(RequestParameter.ID,
+ projectId));
+ }
+ });
- registerHandler(eventBus.addHandler(UpdateEvent.getType(), new UpdateHandler() {
+ view.getMonitoredPointsAddButton().addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void componentSelected(final ButtonEvent event) {
+ eventBus.navigateRequest(Page.REMINDER_EDIT.requestWith(RequestParameter.TYPE, ReminderType.MONITORED_POINT).addParameter(RequestParameter.ID,
+ projectId));
+ }
+ });
+
+ // --
+ // Update event handler.
+ // --
+ registerHandler(eventBus.addHandler(UpdateEvent.getType(), new UpdateHandler() {
+
+ @Override
+ public void onUpdate(final UpdateEvent event) {
+ if (event.concern(UpdateEvent.CALENDAR_EVENT_UPDATE)) {
+ calendar.refresh();
+ }
- @Override
- public void onUpdate(final UpdateEvent event) {
- if (event.concern(UpdateEvent.CALENDAR_EVENT_UPDATE)) {
- calendar.refresh();
- }
-
if (event.concern(UpdateEvent.REMINDER_UPDATED)) {
// TODO appel
reloadEventsOfReminderType((ReminderType) event.getParam(0));
calendar.refresh();
}
- }
- }));
- }
-
- /**
- * Reloads the calendars data (if necessary).
- *
- * @param calendars
- * The calendar types with their corresponding identifier.
- */
- public void reload(final Map calendars, boolean editable) {
- Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh.");
-
- calendar.refresh();
- Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "calendar.refresh ended.");
+ }
+ }));
+ }
+
+ /**
+ * Reloads the calendars data (if necessary).
+ *
+ * @param calendars The calendar types with their corresponding identifier.
+ */
+ public void reload(final Map calendars, boolean editable) {
+ Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh.");
+ calendar.refresh();
+
+ Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "calendar.refresh ended.");
this.projectId = calendars.get(CalendarType.Activity);
- view.setAddEventButtonEnabled(editable);
- Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh.");
- reloadEvents(calendars);
- }
-
- /**
- * {@inheritDoc}
- * Updates the calendar view.
- */
- @Override
- public void onViewRevealed() {
- calendar.refresh();
- }
-
- /**
- * Returns the {@link CalendarWrapper} list from the view store.
- *
- * @return The collection.
- */
- private List getCalendars() {
-
- final List calendars = new ArrayList();
- final ListStore store = view.getCalendarsStore();
-
- for (int i = 0; i < store.getCount(); i++) {
- calendars.add(store.getAt(i));
- }
-
- return calendars;
- }
-
- /**
- * Reloads the calendar events using a {@link GetCalendar} command.
- *
- * @param calendars
- * The calendar types with their corresponding identifier.
- */
- private void reloadEvents(final Map calendars) {
-
- view.getCalendarsStore().removeAll();
-
- if (ClientUtils.isEmpty(calendars)) {
- calendar.refresh();
- Profiler.INSTANCE.endScenario(Scenario.AGENDA);
- return;
- }
-
- final DispatchQueue queue = new DispatchQueue(dispatch, true) {
-
- @Override
- protected void onComplete() {
- calendar.refresh();
- Profiler.INSTANCE.endScenario(Scenario.AGENDA);
- }
- };
-
- for (final Entry calendarEntry : calendars.entrySet()) {
-
- if (calendarEntry == null) {
- continue;
- }
-
- final CalendarType calendarType = calendarEntry.getKey();
- final Integer calendarId = calendarEntry.getValue();
-
- queue.add(new GetCalendar(calendarType, CalendarType.getIdentifier(calendarType, calendarId)), new CommandResultHandler() {
-
- @Override
- public void onCommandSuccess(final Calendar result) {
- Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended.");
- if(result != null) {
- // Defines the color index of the calendar.
- result.setStyle(calendarType.getColorCode());
+ view.setAddEventButtonEnabled(editable);
+ Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before refresh.");
+ reloadEvents(calendars);
+ }
+
+ /**
+ * {@inheritDoc}
+ * Updates the calendar view.
+ */
+ @Override
+ public void onViewRevealed() {
+ calendar.refresh();
+ }
+
+ /**
+ * Returns the {@link CalendarWrapper} list from the view store.
+ *
+ * @return The collection.
+ */
+ private List getCalendars() {
+
+ final List calendars = new ArrayList();
+ final ListStore store = view.getCalendarsStore();
+
+ for (int i = 0; i < store.getCount(); i++) {
+ calendars.add(store.getAt(i));
+ }
+
+ return calendars;
+ }
+
+ /**
+ * Reloads the calendar events using a {@link GetCalendar} command.
+ *
+ * @param calendars The calendar types with their corresponding identifier.
+ */
+ private void reloadEvents(final Map calendars) {
+
+ view.getCalendarsStore().removeAll();
+
+ if (ClientUtils.isEmpty(calendars)) {
+ calendar.refresh();
+ Profiler.INSTANCE.endScenario(Scenario.AGENDA);
+ return;
+ }
+
+ final DispatchQueue queue = new DispatchQueue(dispatch, true) {
+
+ @Override
+ protected void onComplete() {
+ calendar.refresh();
+ Profiler.INSTANCE.endScenario(Scenario.AGENDA);
+ }
+ };
+
+ for (final Entry calendarEntry : calendars.entrySet()) {
+
+ if (calendarEntry == null) {
+ continue;
+ }
+
+ final CalendarType calendarType = calendarEntry.getKey();
+ final Integer calendarId = calendarEntry.getValue();
+
+ queue.add(new GetCalendar(calendarType, CalendarType.getIdentifier(calendarType, calendarId)), new CommandResultHandler() {
+
+ @Override
+ public void onCommandSuccess(final Calendar result) {
+ Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended.");
+ if (result != null) {
+ // Defines the color index of the calendar.
+ result.setStyle(calendarType.getColorCode());
result.setType(calendarType);
- view.getCalendarsStore().add(new CalendarWrapper(result));
- view.getCalendarsSelectionModel().select(view.getCalendarsStore().getCount() - 1, true);
- }
- }
-
- @Override
- protected void onCommandFailure(Throwable caught) {
- Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended with error.");
- super.onCommandFailure(caught);
- }
-
- });
- }
- Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before queue started.");
- queue.start();
- }
+ view.getCalendarsStore().add(new CalendarWrapper(result));
+ view.getCalendarsSelectionModel().select(view.getCalendarsStore().getCount() - 1, true);
+ }
+ }
+
+ @Override
+ protected void onCommandFailure(Throwable caught) {
+ Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, calendarType + " ended with error.");
+ super.onCommandFailure(caught);
+ }
+
+ });
+ }
+ Profiler.INSTANCE.markCheckpoint(Scenario.AGENDA, "Before queue started.");
+ queue.start();
+ }
+
/**
* Reload a given type of reminder into the calendar.
- *
+ *
* @param reminderType Type of reminder to refresh.
*/
private void reloadEventsOfReminderType(final ReminderType reminderType) {
final CalendarType calendarType = reminderType == ReminderType.REMINDER ? CalendarType.Reminder : CalendarType.MonitoredPoint;
-
+
final List calendars = calendar.getCalendars();
for (int index = 0; index < calendars.size(); index++) {
final Calendar currentCalendar = calendars.get(index);
-
+
if (currentCalendar.getType() == calendarType) {
final GetCalendar getCalendar = new GetCalendar(calendarType, currentCalendar.getIdentifier());
final int location = index;
-
+
dispatch.execute(getCalendar, new CommandResultHandler() {
-
+
@Override
protected void onCommandSuccess(Calendar result) {
- if(result != null) {
+ if (result != null) {
result.setStyle(calendarType.getColorCode());
result.setType(calendarType);
calendars.set(location, result);
calendar.refresh();
}
}
-
});
return;
}
diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java
index 85cf61775..dc7d1ca5c 100644
--- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java
+++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarEventView.java
@@ -21,7 +21,10 @@
* .
* #L%
*/
-
+import com.extjs.gxt.ui.client.Style;
+import com.extjs.gxt.ui.client.event.Events;
+import com.extjs.gxt.ui.client.event.FieldEvent;
+import com.extjs.gxt.ui.client.event.Listener;
import org.sigmah.client.i18n.I18N;
import org.sigmah.client.ui.presenter.calendar.CalendarEventPresenter;
import org.sigmah.client.ui.res.icon.IconImageBundle;
@@ -32,140 +35,876 @@
import org.sigmah.client.ui.widget.popup.PopupWidget;
import org.sigmah.shared.dto.calendar.Event;
-import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.DateField;
+import com.extjs.gxt.ui.client.widget.form.Radio;
+import com.extjs.gxt.ui.client.widget.form.RadioGroup;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.TimeField;
+import com.extjs.gxt.ui.client.widget.form.CheckBox;
+import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.google.inject.Singleton;
+import com.extjs.gxt.ui.client.widget.HorizontalPanel;
+import com.extjs.gxt.ui.client.widget.VerticalPanel;
+import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
+import com.google.gwt.user.client.ui.HTML;
+import java.util.Date;
+/*
+import com.gwtext.client.data.Record;
+import com.gwtext.client.data.SimpleStore;
+import com.gwtext.client.data.Store;
+import com.gwtext.client.widgets.Panel;
+import com.gwtext.client.widgets.form.ComboBox;
+import com.gwtext.client.widgets.form.FormPanel;
+import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
+ */
/**
* Calendar event edit frame view used to create/edit a calendar event.
- *
+ *
* @author Denis Colliot (dcolliot@ideia.fr)
*/
@Singleton
public class CalendarEventView extends AbstractPopupView implements CalendarEventPresenter.View {
- private FormPanel form;
- private TextField eventSummaryField;
- private DateField eventDateField;
- private TimeField eventStartTimeField;
- private TimeField eventEndTimeField;
- private TextArea eventDescriptionField;
-
- private Button saveButton;
- private Button cancelButton;
-
- /**
- * Builds the view.
- */
- public CalendarEventView() {
- super(new PopupWidget(true), 500);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void initialize() {
-
- form = Forms.panel();
-
- eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true);
- eventSummaryField.setName(Event.SUMMARY);
-
- eventDateField = Forms.date(I18N.CONSTANTS.calendarEventDate(), true);
- eventDateField.setName(Event.DATE);
-
- eventStartTimeField = Forms.time(I18N.CONSTANTS.calendarEventStartHour(), false);
- eventStartTimeField.setName(Event.START_TIME);
- eventStartTimeField.setTriggerAction(TriggerAction.ALL);
-
- eventEndTimeField = Forms.time(I18N.CONSTANTS.calendarEventEndHour(), false);
- eventEndTimeField.setName(Event.END_TIME);
- eventEndTimeField.setTriggerAction(TriggerAction.ALL);
-
- eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false);
- eventDescriptionField.setName(Event.DESCRIPTION);
-
- saveButton = Forms.button(I18N.CONSTANTS.formWindowSubmitAction(), IconImageBundle.ICONS.save());
- cancelButton = Forms.button(I18N.CONSTANTS.cancel());
-
- form.add(eventSummaryField);
- form.add(eventDateField);
- form.add(eventStartTimeField);
- form.add(eventEndTimeField);
- form.add(eventDescriptionField);
-
- form.addButton(cancelButton);
- form.addButton(saveButton);
-
- initPopup(form);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public FormPanel getForm() {
- return form;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public TextField getEventSummaryField() {
- return eventSummaryField;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public DateField getEventDateField() {
- return eventDateField;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public TimeField getEventStartTimeField() {
- return eventStartTimeField;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public TimeField getEventEndTimeField() {
- return eventEndTimeField;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public TextArea getEventDescriptionField() {
- return eventDescriptionField;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getSaveButton() {
- return saveButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getCancelButton() {
- return cancelButton;
- }
+ private FormPanel form;
+ private TextField eventSummaryField;
+ private DateField eventDateStartField;
+ private DateField eventDateEndField;
+ private TimeField eventStartTimeField;
+ private TimeField eventEndTimeField;
+ private TextArea eventDescriptionField;
+
+ private Button saveButton;
+ private Button cancelButton;
+
+ private CheckBox allDayCheckbox;
+ private RadioGroup yearlyVariantRG;
+ private RadioGroup montlyVariantRG;
+ private FieldSet panelYearly;
+ private FieldSet panelMonthly;
+ private FieldSet panelWeekly;
+ private FieldSet panelDaily;
+ private FieldSet monthlyRepSettings;
+ private FieldSet yearlyRepSettings;
+
+ private Radio yearlySameDayOfWeekRB;
+ private Radio yearlySameDateRB;
+
+ private Radio onceRepeatRB;
+ private Radio dailyRepeatRB;
+ private Radio weeklyRepeatRB;
+ private Radio monthlyRepeatRB;
+ private Radio yearlyRepeatRB;
+ private Radio radioMonthlySameDate;
+ private Radio radioMonthlySameDayOfWeek;
+ private Radio radioNumberOfRepetitions;
+ private Radio radioRepetitionEndDate;
+
+ private Radio radioWeeklyNumberOfRepetitions;
+ private Radio radioWeeklyRepetitionEndDate;
+ private Radio radioYearlyNumberOfRepetitions;
+ private Radio radioYearlyRepetitionEndDate;
+ private Radio radioDailyNumberOfRepetitions;
+ private Radio radioDailyRepetitionEndDate;
+
+ private DateField repetitionEndDate;
+ private TextArea numberOfRepetitions;
+ private DateField dailyRepetitionEndDate;
+ private TextArea dailyNumberOfRepetitions;
+ private DateField weeklyRepetitionEndDate;
+ private TextArea weeklyNumberOfRepetitions;
+ private DateField yearlyRepetitionEndDate;
+ private TextArea yearlyNumberOfRepetitions;
+ // private CheckBoxGroup allDayCheckboxGr;
+
+ private RadioGroup RepeatEventPeriodRG;
+ private RadioGroup RepeatMultiEventPeriodRG;
+ private RadioGroup RepeatYearlyMultiEventPeriodRG;
+ private RadioGroup RepeatWeeklyMultiEventPeriodRG;
+ private RadioGroup RepeatDailyMultiEventPeriodRG;
+
+ /**
+ * Builds the view.
+ */
+ public CalendarEventView() {
+ super(new PopupWidget(true), 500);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void initialize() {
+ form = Forms.panel();
+
+ createYearlyPanel();
+ createMonthlyPanel();
+ createWeeklyPanel();
+ createDailyPanel();
+ createRepeatEventPeriodRadioGroup();
+
+ eventSummaryField = Forms.text(I18N.CONSTANTS.calendarEventObject(), true);
+ eventSummaryField.setName(Event.SUMMARY);
+
+ eventDateStartField = Forms.date(I18N.CONSTANTS.calendar_addEvent_dateStart_label(), true);
+ eventDateStartField.setName(Event.DATE);
+
+ eventStartTimeField = Forms.time(I18N.CONSTANTS.calendarEventStartHour(), false);
+ eventStartTimeField.setName(Event.START_TIME);
+ eventStartTimeField.setTriggerAction(TriggerAction.ALL);
+
+ eventEndTimeField = Forms.time(I18N.CONSTANTS.calendarEventEndHour(), false);
+ eventEndTimeField.setName(Event.END_TIME);
+ eventEndTimeField.setTriggerAction(TriggerAction.ALL);
+
+ eventDateEndField = Forms.date(I18N.CONSTANTS.calendar_addEvent_dateEnd_label(), false);
+ eventDateEndField.setName(Event.DATE + "888end");
+
+ eventDescriptionField = Forms.textarea(I18N.CONSTANTS.calendarEventDescription(), false);
+ eventDescriptionField.setName(Event.DESCRIPTION);
+ eventDescriptionField.setId(Event.DESCRIPTION);
+ eventDescriptionField.setMaxLength(255);
+
+ saveButton = Forms.button(I18N.CONSTANTS.formWindowSubmitAction(), IconImageBundle.ICONS.save());
+ cancelButton = Forms.button(I18N.CONSTANTS.cancel());
+
+ form.add(eventSummaryField);
+ form.add(eventDateStartField);
+ form.add(eventDateEndField);
+ form.add(createAllDayCheckbox());
+
+ form.add(eventStartTimeField);
+ form.add(eventEndTimeField);
+ form.add(RepeatEventPeriodRG);
+ form.add(panelYearly);
+ form.add(panelMonthly);
+ form.add(panelWeekly);
+ form.add(panelDaily);
+ form.add(eventDescriptionField);
+
+ form.addButton(cancelButton);
+ form.addButton(saveButton);
+
+ initPopup(form);
+ }
+
+ private CheckBox createAllDayCheckbox() {
+
+ allDayCheckbox = Forms.checkbox(I18N.CONSTANTS.calendar_addEvent_isAllDayCB_boxLabel(), I18N.CONSTANTS.calendar_addEvent_isAllDayCB_allDayName(), false);
+ allDayCheckbox.setFieldLabel(I18N.CONSTANTS.calendar_addEvent_allDayCbGr_label());
+ allDayCheckbox.validate(false);
+ allDayCheckbox.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ eventStartTimeField.setVisible(!allDayCheckbox.getValue());
+ eventEndTimeField.setVisible(!allDayCheckbox.getValue());
+ }
+ });
+
+ return allDayCheckbox;
+ }
+
+ private void createRepeatEventPeriodRadioGroup() {
+ createOnceRb();
+ createDailyRb();
+ createWeeklyRb();
+ createMonthlyRb();
+ createYearlyRb();
+
+ RepeatEventPeriodRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_label(),
+ I18N.CONSTANTS.calendar_addEvent_repeatPeriodRG_name(),
+ Style.Orientation.HORIZONTAL,
+ onceRepeatRB,
+ dailyRepeatRB,
+ weeklyRepeatRB,
+ monthlyRepeatRB,
+ yearlyRepeatRB);
+ RepeatEventPeriodRG.setSelectionRequired(Boolean.TRUE);
+ RepeatEventPeriodRG.enable();
+ }
+
+ private void createYearlyRb() {
+ yearlyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_label(), Boolean.FALSE);
+ yearlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatYearlyRB_toolTip());
+ yearlyRepeatRB.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ //add default description
+ //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_yearly());
+ getPanelYearly().setVisible(getYearlyRepeatRB().getValue());
+ getPanelWeekly().setVisible(!yearlyRepeatRB.getValue());
+ getPanelMonthly().setVisible(!yearlyRepeatRB.getValue());
+ getPanelDaily().setVisible(!yearlyRepeatRB.getValue());
+
+ getYearlySameDateRB().show();
+ getYearlySameDayOfWeekRB().show();
+ getYearlySameDateRB().setValue(true);
+ eventDateStartField.setAllowBlank(false);
+ }
+ });
+ }
+
+ private void createMonthlyRb() {
+ monthlyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_label(), Boolean.FALSE);
+ monthlyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatMonthlyRB_toolTip());
+ monthlyRepeatRB.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ //add default description
+ //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_monthly());
+ getPanelWeekly().setVisible(!monthlyRepeatRB.getValue());
+ getPanelYearly().setVisible(!monthlyRepeatRB.getValue());
+ getPanelDaily().setVisible(!monthlyRepeatRB.getValue());
+ getPanelMonthly().setVisible(getMonthlyRepeatRB().getValue());
+ eventDateStartField.setAllowBlank(false);
+ getRadioMonthlySameDate().show();
+ getRadioMonthlySameDayOfWeek().show();
+ getRadioMonthlySameDayOfWeek().setValue(true);
+ }
+ });
+ }
+
+ private void createWeeklyRb() {
+ weeklyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_label(), Boolean.FALSE);
+ weeklyRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatWeeklyRB_toolTip());
+ weeklyRepeatRB.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ //add default description
+ //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_weekly());
+ getPanelYearly().setVisible(!weeklyRepeatRB.getValue());
+ getPanelMonthly().setVisible(!weeklyRepeatRB.getValue());
+ getPanelDaily().setVisible(!weeklyRepeatRB.getValue());
+ getPanelWeekly().setVisible(getWeeklyRepeatRB().getValue());
+ // Window.alert("Test");
+ eventDateStartField.setAllowBlank(false);
+ }
+ });
+ }
+
+ /**
+ *
+ */
+ private void createDailyRb() {
+ dailyRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatDailyRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatDailyRB_label(), Boolean.FALSE);
+ dailyRepeatRB.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ //add default description
+ //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_daily());
+ getPanelYearly().setVisible(!dailyRepeatRB.getValue());
+ getPanelMonthly().setVisible(!dailyRepeatRB.getValue());
+ getPanelWeekly().setVisible(!dailyRepeatRB.getValue());
+ getPanelDaily().setVisible(getDailyRepeatRB().getValue());
+ }
+ });
+ }
+
+ private void createOnceRb() {
+ onceRepeatRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_label(), I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_name(), Boolean.FALSE);
+ onceRepeatRB.setOriginalValue(Boolean.TRUE);
+ onceRepeatRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatOnceRB_toolTip());
+
+ onceRepeatRB.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+
+ getPanelYearly().setVisible(!onceRepeatRB.getValue());
+ getPanelMonthly().setVisible(!onceRepeatRB.getValue());
+ getPanelWeekly().setVisible(!onceRepeatRB.getValue());
+ getPanelDaily().setVisible(!onceRepeatRB.getValue());
+ //add default description
+ //((TextArea) form.getItemByItemId(Event.DESCRIPTION)).setValue(I18N.CONSTANTS.calendar_addEvent_description_textArea_once());
+ }
+ });
+ }
+
+ private void createDailyPanel() {
+ panelDaily = new FieldSet();
+ panelDaily.setExpanded(true);
+ panelDaily.setBorders(true);
+ panelDaily.setHeadingHtml("Daily repetition details");
+ panelDaily.setAutoHeight(true);
+ panelDaily.setVisible(false);
+
+ radioDailyNumberOfRepetitions = Forms.radio("Number of repetitions");
+ radioDailyNumberOfRepetitions.setName("Number of repetitonsYearly");
+ radioDailyNumberOfRepetitions.setValue(Boolean.FALSE);
+ radioDailyNumberOfRepetitions.setOriginalValue(Boolean.FALSE);
+ radioDailyNumberOfRepetitions.setToolTip("Set a number of repetitons (Yearly)");
+
+ dailyNumberOfRepetitions = Forms.textarea("", false);
+ dailyNumberOfRepetitions.setName("numberOfRepetitionsyearly");
+ dailyNumberOfRepetitions.setId("numberOfRepetitionsyearly");
+ dailyNumberOfRepetitions.setMaxLength(255);
+ dailyNumberOfRepetitions.setHeight(19);
+
+ radioDailyRepetitionEndDate = Forms.radio("Repetition end date");
+ radioDailyRepetitionEndDate.setBoxLabel("Repetition end date");
+ radioDailyRepetitionEndDate.setName("Repetition end dateyearly");
+ radioDailyRepetitionEndDate.setValue(Boolean.FALSE);
+ radioDailyRepetitionEndDate.setToolTip("Set a repetition end date");
+
+ dailyRepetitionEndDate = Forms.date("", true);
+ dailyRepetitionEndDate.setName("RepetitionEndDateFieldyearly");
+ dailyNumberOfRepetitions.disable();
+ dailyRepetitionEndDate.disable();
+
+ radioDailyNumberOfRepetitions.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ dailyNumberOfRepetitions.enable();
+ dailyRepetitionEndDate.disable();
+ }
+ });
+
+ radioDailyRepetitionEndDate.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+
+ dailyRepetitionEndDate.enable();
+ dailyNumberOfRepetitions.disable();
+ }
+ });
+
+ RepeatDailyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly",
+ "Multi-event periodRGyearly",
+ Style.Orientation.VERTICAL,
+ radioDailyNumberOfRepetitions,
+ radioDailyRepetitionEndDate);
+ RepeatDailyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE);
+ RepeatDailyMultiEventPeriodRG.enable();
+
+ //panelMonthly.add(RepeatMultiEventPeriodRG);
+ VerticalPanel verticalPanel = new VerticalPanel();
+ verticalPanel.add(dailyNumberOfRepetitions);
+ verticalPanel.add(dailyRepetitionEndDate);
+ HorizontalPanel horizontalPanel = new HorizontalPanel();
+ horizontalPanel.add(RepeatDailyMultiEventPeriodRG);
+ horizontalPanel.add(verticalPanel);
+
+ panelDaily.add(horizontalPanel);
+ }
+
+ private void createWeeklyPanel() {
+ panelWeekly = new FieldSet();
+ panelWeekly.setExpanded(true);
+ panelWeekly.setBorders(true);
+ panelWeekly.setHeadingHtml("Weekly repetition details");
+ panelWeekly.setAutoHeight(true);
+ panelWeekly.setVisible(false);
+
+ radioWeeklyNumberOfRepetitions = Forms.radio("Number of repetitions");
+ radioWeeklyNumberOfRepetitions.setName("Number of repetitonsYearly");
+ radioWeeklyNumberOfRepetitions.setValue(Boolean.FALSE);
+ radioWeeklyNumberOfRepetitions.setOriginalValue(Boolean.FALSE);
+ radioWeeklyNumberOfRepetitions.setToolTip("Set a number of repetitons");
+
+ weeklyNumberOfRepetitions = Forms.textarea("", false);
+ weeklyNumberOfRepetitions.setName("numberOfRepetitionsyearly");
+ weeklyNumberOfRepetitions.setId("numberOfRepetitionsyearly");
+ weeklyNumberOfRepetitions.setMaxLength(255);
+ weeklyNumberOfRepetitions.setHeight(19);
+
+ radioWeeklyRepetitionEndDate = Forms.radio("Repetition end date");
+ radioWeeklyRepetitionEndDate.setBoxLabel("Repetition end date");
+ radioWeeklyRepetitionEndDate.setName("Repetition end dateyearly");
+ radioWeeklyRepetitionEndDate.setValue(Boolean.FALSE);
+ radioWeeklyRepetitionEndDate.setToolTip("Set a repetition end date");
+
+ weeklyRepetitionEndDate = Forms.date("", true);
+ weeklyRepetitionEndDate.setName("RepetitionEndDateFieldyearly");
+ weeklyNumberOfRepetitions.disable();
+ weeklyRepetitionEndDate.disable();
+
+ radioWeeklyNumberOfRepetitions.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ weeklyNumberOfRepetitions.enable();
+ weeklyRepetitionEndDate.disable();
+ }
+ });
+
+ radioWeeklyRepetitionEndDate.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+
+ weeklyRepetitionEndDate.enable();
+ weeklyNumberOfRepetitions.disable();
+ }
+ });
+
+ RepeatWeeklyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly",
+ "Multi-event periodRGyearly",
+ Style.Orientation.VERTICAL,
+ radioWeeklyNumberOfRepetitions,
+ radioWeeklyRepetitionEndDate);
+ RepeatWeeklyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE);
+ RepeatWeeklyMultiEventPeriodRG.enable();
+
+ //panelMonthly.add(RepeatMultiEventPeriodRG);
+ VerticalPanel verticalPanel = new VerticalPanel();
+ verticalPanel.add(weeklyNumberOfRepetitions);
+ verticalPanel.add(weeklyRepetitionEndDate);
+ HorizontalPanel horizontalPanel = new HorizontalPanel();
+ horizontalPanel.add(RepeatWeeklyMultiEventPeriodRG);
+ horizontalPanel.add(verticalPanel);
+
+ panelWeekly.add(horizontalPanel);
+ }
+
+ private void createMonthlyPanel() {
+ panelMonthly = new FieldSet();
+ panelMonthly.setExpanded(true);
+ panelMonthly.setBorders(true);
+ panelMonthly.setHeadingHtml(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_headingHtml_monthly());
+ panelMonthly.setAutoHeight(true);
+ panelMonthly.setVisible(false);
+
+ radioMonthlySameDayOfWeek = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_label());
+ radioMonthlySameDayOfWeek.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_monthly_name());
+ radioMonthlySameDayOfWeek.setValue(Boolean.FALSE);
+ radioMonthlySameDayOfWeek.setOriginalValue(Boolean.FALSE);
+ radioMonthlySameDayOfWeek.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_monthly_toolTip());
+
+ radioMonthlySameDate = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label());
+ radioMonthlySameDate.setBoxLabel(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label());
+ radioMonthlySameDate.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_monthly_name());
+ radioMonthlySameDate.setValue(Boolean.FALSE);
+ radioMonthlySameDate.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_monthly_toolTip());
+
+ montlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_monthly_settings());
+ montlyVariantRG.setSelectionRequired(Boolean.FALSE);
+ montlyVariantRG.setOrientation(Style.Orientation.HORIZONTAL);
+ montlyVariantRG.add(radioMonthlySameDayOfWeek);
+ montlyVariantRG.add(radioMonthlySameDate);
+ panelMonthly.add(montlyVariantRG);
+
+ radioNumberOfRepetitions = Forms.radio("Number of repetitions");
+ radioNumberOfRepetitions.setName("Number of repetitons");
+ radioNumberOfRepetitions.setValue(Boolean.FALSE);
+ radioNumberOfRepetitions.setOriginalValue(Boolean.FALSE);
+ radioNumberOfRepetitions.setToolTip("Set a number of repetitions");
+
+ radioRepetitionEndDate = Forms.radio("Repetition end date");
+ radioRepetitionEndDate.setBoxLabel("Repetition end date");
+ radioRepetitionEndDate.setName("Repetition end date");
+ radioRepetitionEndDate.setValue(Boolean.FALSE);
+ radioRepetitionEndDate.setToolTip("Set a repetition end date");
+
+ RepeatMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRG");
+ RepeatMultiEventPeriodRG.setSelectionRequired(Boolean.FALSE);
+ RepeatMultiEventPeriodRG.setOrientation(Style.Orientation.VERTICAL);
+ RepeatMultiEventPeriodRG.add(radioNumberOfRepetitions);
+ RepeatMultiEventPeriodRG.add(radioRepetitionEndDate);
+ panelMonthly.add(RepeatMultiEventPeriodRG);
+
+ numberOfRepetitions = Forms.textarea("", false);
+ numberOfRepetitions.setName("numberOfRepetitions");
+ numberOfRepetitions.setId("numberOfRepetitions");
+ numberOfRepetitions.setMaxLength(255);
+ numberOfRepetitions.setHeight(19);
+
+ repetitionEndDate = Forms.date("", true);
+ repetitionEndDate.setName("RepetitionEndDateField");
+ repetitionEndDate.setData("", new Date());
+
+ radioNumberOfRepetitions.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ numberOfRepetitions.enable();
+ repetitionEndDate.disable();
+ }
+ });
+
+ radioRepetitionEndDate.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+
+ repetitionEndDate.enable();
+ numberOfRepetitions.disable();
+ }
+ });
+
+ /* monthlyRepSettings = new FieldSet();
+ monthlyRepSettings.setExpanded(true);
+ monthlyRepSettings.setBorders(true);
+ monthlyRepSettings.setHeadingHtml("End of monthly repetition event");
+ monthlyRepSettings.setAutoHeight(true);
+ monthlyRepSettings.setVisible(true);*/
+ VerticalPanel verticalPanel = new VerticalPanel();
+ VerticalPanel verticalPanel1 = new VerticalPanel();
+ VerticalPanel verticalPanel2 = new VerticalPanel();
+ VerticalPanel verticalPanel3 = new VerticalPanel();
+ verticalPanel3.setHeight(5);
+ verticalPanel1.add(numberOfRepetitions);
+ verticalPanel2.add(repetitionEndDate);
+
+ verticalPanel.add(verticalPanel1);
+ verticalPanel.add(verticalPanel3);
+ verticalPanel.add(verticalPanel2);
+
+ HorizontalPanel horizontalPanel = new HorizontalPanel();
+ horizontalPanel.add(RepeatMultiEventPeriodRG);
+ horizontalPanel.add(verticalPanel);
+ panelMonthly.add(new HTML("
"));
+ panelMonthly.add(horizontalPanel);
+ // verticalPanel1.setHeight(verticalPanel.getHeight()/2);
+ //verticalPanel2.setHeight(verticalPanel.getHeight()/2);
+ }
+
+ private void createYearlyPanel() {
+ panelYearly = new FieldSet();
+ panelYearly.setExpanded(true);
+ panelYearly.setBorders(true);
+ panelYearly.setHeadingHtml(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_headingHtml_yearly());
+ panelYearly.setAutoHeight(true);
+ panelYearly.setVisible(false);
+
+ yearlySameDayOfWeekRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_label(), Boolean.FALSE);
+ yearlySameDayOfWeekRB.setToolTip(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_yearly_toolTip());
+ yearlySameDayOfWeekRB.setOriginalValue(Boolean.TRUE);
+ yearlySameDayOfWeekRB.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDayOfWeekRB_yearly_name());
+ yearlySameDayOfWeekRB.setValue(Boolean.TRUE);
+
+ yearlySameDateRB = Forms.radio(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_label(), Boolean.FALSE);
+ yearlySameDateRB.setName(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_SameDateRB_yearly_name());
+ yearlyVariantRG = Forms.radioGroup(I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings(),
+ I18N.CONSTANTS.calendar_addEvent_repeatsSettings_radioGroup_yearly_settings_name(),
+ Style.Orientation.HORIZONTAL,
+ yearlySameDayOfWeekRB,
+ yearlySameDateRB);
+ yearlyVariantRG.setSelectionRequired(Boolean.FALSE);
+ panelYearly.add(yearlyVariantRG);
+
+ radioYearlyNumberOfRepetitions = Forms.radio("Number of repetitions");
+ radioYearlyNumberOfRepetitions.setName("Number of repetitionsYearly");
+ radioYearlyNumberOfRepetitions.setValue(Boolean.FALSE);
+ radioYearlyNumberOfRepetitions.setOriginalValue(Boolean.FALSE);
+ radioYearlyNumberOfRepetitions.setToolTip("Set a number of repetitons");
+
+ yearlyNumberOfRepetitions = Forms.textarea("", false);
+ yearlyNumberOfRepetitions.setName("numberOfRepetitionsyearly");
+ yearlyNumberOfRepetitions.setId("numberOfRepetitionsyearly");
+ yearlyNumberOfRepetitions.setMaxLength(255);
+ yearlyNumberOfRepetitions.setHeight(19);
+
+ radioYearlyRepetitionEndDate = Forms.radio("Repetition end date");
+ radioYearlyRepetitionEndDate.setBoxLabel("Repetition end date");
+ radioYearlyRepetitionEndDate.setName("Repetition end dateyearly");
+ radioYearlyRepetitionEndDate.setValue(Boolean.FALSE);
+ radioYearlyRepetitionEndDate.setToolTip("Set a repetition end date");
+
+ yearlyRepetitionEndDate = Forms.date("", true);
+ yearlyRepetitionEndDate.setName("RepetitionEndDateFieldyearly");
+ yearlyNumberOfRepetitions.disable();
+ yearlyRepetitionEndDate.disable();
+
+ radioYearlyNumberOfRepetitions.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+ yearlyNumberOfRepetitions.enable();
+ yearlyRepetitionEndDate.disable();
+ }
+ });
+
+ radioYearlyRepetitionEndDate.addListener(Events.OnChange, new Listener() {
+ @Override
+ public void handleEvent(FieldEvent event) {
+
+ yearlyRepetitionEndDate.enable();
+ yearlyNumberOfRepetitions.disable();
+ }
+ });
+
+ RepeatYearlyMultiEventPeriodRG = Forms.radioGroup("Multi-event periodRGyearly",
+ "Multi-event periodRGyearly",
+ Style.Orientation.VERTICAL,
+ radioYearlyNumberOfRepetitions,
+ radioYearlyRepetitionEndDate);
+ RepeatYearlyMultiEventPeriodRG.setSelectionRequired(Boolean.TRUE);
+ RepeatYearlyMultiEventPeriodRG.enable();
+
+ //panelMonthly.add(RepeatMultiEventPeriodRG);
+ VerticalPanel verticalPanel = new VerticalPanel();
+
+ VerticalPanel verticalPanel1 = new VerticalPanel();
+ VerticalPanel verticalPanel2 = new VerticalPanel();
+ verticalPanel1.setHeight(23);
+ verticalPanel1.setWidth(150);
+ verticalPanel1.add(yearlyNumberOfRepetitions);
+ verticalPanel2.setHeight(23);
+ verticalPanel2.setWidth(150);
+ verticalPanel2.add(yearlyRepetitionEndDate);
+ VerticalPanel verticalPanel3 = new VerticalPanel();
+ verticalPanel3.setHeight(5);
+
+ verticalPanel.add(verticalPanel1);
+ verticalPanel.add(verticalPanel3);
+ verticalPanel.add(verticalPanel2);
+
+ HorizontalPanel horizontalPanel = new HorizontalPanel();
+ horizontalPanel.add(RepeatYearlyMultiEventPeriodRG);
+ horizontalPanel.add(verticalPanel);
+
+ panelYearly.add(new HTML("
"));
+ panelYearly.add(horizontalPanel);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public FormPanel getForm() {
+ return form;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public TextField getEventSummaryField() {
+ return eventSummaryField;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public DateField getEventDateStartField() {
+ return eventDateStartField;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public DateField getEventDateEndField() {
+ return eventDateEndField;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public TimeField getEventStartTimeField() {
+ return eventStartTimeField;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public TimeField getEventEndTimeField() {
+ return eventEndTimeField;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public TextArea getEventDescriptionField() {
+ return eventDescriptionField;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getSaveButton() {
+ return saveButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getCancelButton() {
+ return cancelButton;
+ }
+
+ @Override
+ public CheckBox getAllDayCheckbox() {
+ return allDayCheckbox;
+ }
+
+ @Override
+ public FieldSet getPanelYearly() {
+ return panelYearly;
+ }
+
+ @Override
+ public FieldSet getMonthlyRepSettings() {
+ return monthlyRepSettings;
+ }
+
+ @Override
+ public FieldSet getYearlyRepSettings() {
+ return yearlyRepSettings;
+ }
+
+ @Override
+ public FieldSet getPanelMonthly() {
+ return panelMonthly;
+ }
+
+ @Override
+ public FieldSet getPanelWeekly() {
+ return panelWeekly;
+ }
+
+ @Override
+ public FieldSet getPanelDaily() {
+ return panelDaily;
+ }
+
+ /**
+ *
+ * @return
+ */
+ @Override
+ public Radio getOnceRepeatRB() {
+ return onceRepeatRB;
+ }
+
+ @Override
+ public Radio getDailyRepeatRB() {
+ return dailyRepeatRB;
+ }
+
+ @Override
+ public Radio getWeeklyRepeatRB() {
+ return weeklyRepeatRB;
+ }
+
+ @Override
+ public Radio getMonthlyRepeatRB() {
+ return monthlyRepeatRB;
+ }
+
+ @Override
+ public Radio getYearlyRepeatRB() {
+ return yearlyRepeatRB;
+ }
+
+ @Override
+ public RadioGroup getYearlyVariantRG() {
+ return yearlyVariantRG;
+ }
+
+ @Override
+ public RadioGroup getRepeatMultiEventPeriodRG() {
+ return RepeatMultiEventPeriodRG;
+ }
+
+ @Override
+ public RadioGroup getMontlyVariantRG() {
+ return montlyVariantRG;
+ }
+
+ @Override
+ public Radio getYearlySameDayOfWeekRB() {
+ return yearlySameDayOfWeekRB;
+ }
+
+ @Override
+ public Radio getYearlySameDateRB() {
+ return yearlySameDateRB;
+ }
+
+ @Override
+ public RadioGroup getRepeatEventPeriodRG() {
+ return RepeatEventPeriodRG;
+ }
+
+ @Override
+ public Radio getRadioMonthlySameDate() {
+ return radioMonthlySameDate;
+ }
+
+ @Override
+ public Radio getRadioMonthlySameDayOfWeek() {
+ return radioMonthlySameDayOfWeek;
+ }
+
+ @Override
+ public Radio getRadioNumberOfRepetitions() {
+ return radioNumberOfRepetitions;
+ }
+
+ @Override
+ public Radio getRadioRepetitionEndDate() {
+ return radioRepetitionEndDate;
+ }
+
+ @Override
+ public Radio getYearlyRadioNumberOfRepetitions() {
+ return radioYearlyNumberOfRepetitions;
+ }
+
+ @Override
+ public Radio getYearlyRadioRepetitionEndDate() {
+ return radioYearlyRepetitionEndDate;
+ }
+
+ @Override
+ public Radio getDailyRadioNumberOfRepetitions() {
+ return radioDailyNumberOfRepetitions;
+ }
+
+ @Override
+ public Radio getDailyRadioRepetitionEndDate() {
+ return radioDailyRepetitionEndDate;
+ }
+
+ @Override
+ public Radio getWeeklyRadioNumberOfRepetitions() {
+ return radioWeeklyNumberOfRepetitions;
+ }
+
+ @Override
+ public Radio getWeeklyRadioRepetitionEndDate() {
+ return radioWeeklyRepetitionEndDate;
+ }
+
+ @Override
+ public TextArea getNumberOfRepetitions() {
+ return numberOfRepetitions;
+ }
+
+ @Override
+ public DateField getRepetitionEndDate() {
+ return repetitionEndDate;
+ }
+
+ @Override
+ public TextArea getWeeklyNumberOfRepetitions() {
+ return weeklyNumberOfRepetitions;
+ }
+
+ @Override
+ public DateField getWeeklyRepetitionEndDate() {
+ return weeklyRepetitionEndDate;
+ }
+
+ @Override
+ public TextArea getDailyNumberOfRepetitions() {
+ return dailyNumberOfRepetitions;
+ }
+
+ @Override
+ public DateField getDailyRepetitionEndDate() {
+ return dailyRepetitionEndDate;
+ }
+
+ @Override
+ public TextArea getYearlyNumberOfRepetitions() {
+ return yearlyNumberOfRepetitions;
+ }
+ @Override
+ public DateField getYearlyRepetitionEndDate() {
+ return yearlyRepetitionEndDate;
+ }
}
diff --git a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java
index f6418d16a..957035cc6 100644
--- a/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java
+++ b/src/main/java/org/sigmah/client/ui/view/calendar/CalendarView.java
@@ -21,305 +21,303 @@
* .
* #L%
*/
+import java.util.Arrays;
-
-import java.util.Arrays;
-
-import org.sigmah.client.i18n.I18N;
-import org.sigmah.client.ui.presenter.calendar.CalendarPresenter;
-import org.sigmah.client.ui.view.base.AbstractView;
-import org.sigmah.client.ui.widget.CalendarWidget;
-import org.sigmah.client.ui.widget.button.Button;
-import org.sigmah.client.ui.widget.form.Forms;
-import org.sigmah.client.ui.widget.layout.Layouts;
-import org.sigmah.client.ui.widget.layout.Layouts.Margin;
-import org.sigmah.client.ui.widget.panel.Panels;
-import org.sigmah.shared.dto.calendar.CalendarWrapper;
-
-import com.extjs.gxt.ui.client.Style.LayoutRegion;
-import com.extjs.gxt.ui.client.store.ListStore;
-import com.extjs.gxt.ui.client.widget.Component;
-import com.extjs.gxt.ui.client.widget.ContentPanel;
-import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
-import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
-import com.extjs.gxt.ui.client.widget.grid.ColumnData;
-import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
-import com.extjs.gxt.ui.client.widget.grid.Grid;
-import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
-import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
-import com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel;
-import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
-import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
-import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.i18n.client.LocaleInfo;
-import com.google.gwt.i18n.shared.DateTimeFormatInfo;
-import com.google.gwt.user.client.ui.SimplePanel;
-import org.sigmah.client.ui.res.icon.IconImageBundle;
-
-/**
- * Calendar widget presenter.
- *
- * @author Raphaël Calabro (rcalabro@ideia.fr) (v1.3)
- * @author Denis Colliot (dcolliot@ideia.fr) (v2.0)
- */
-public class CalendarView extends AbstractView implements CalendarPresenter.View {
-
- private ContentPanel calendarView;
-
- private ListStore calendarsStore;
- private CheckBoxSelectionModel selectionModel;
-
- private ToolBar toolbar;
- private Button addEventButton;
- private Button todayButton;
- private Button weekButton;
- private Button monthButton;
- private Button previousButton;
- private Button nextButton;
-
- private Button reminderAddButton;
- private Button monitoredPointsAddButton;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void initialize() {
-
- // --
- // Calendars left panel.
- // --
-
- final BorderLayoutData calendarListData = Layouts.borderLayoutData(LayoutRegion.WEST, Layouts.LEFT_COLUMN_WIDTH);
- calendarListData.setCollapsible(true);
- add(createCalendarsGridPanel(), calendarListData);
-
- // --
- // Calendar center widget.
- // --
-
- add(createCalendarsMainPanel(), Layouts.borderLayoutData(LayoutRegion.CENTER, Margin.LEFT));
- }
-
- /**
- * Creates the calendars panel + grid.
- *
- * @return The calendars panel.
- */
- private Component createCalendarsGridPanel() {
-
- // Calendars panel.
- final ContentPanel calendarsPanel = Panels.content(I18N.CONSTANTS.projectTabCalendar());
-
- // Calendars grid.
- final ColumnConfig calendarName = new ColumnConfig("name", I18N.CONSTANTS.name(), 180);
- final ColumnConfig calendarColor = new ColumnConfig("color", "", 20);
- calendarColor.setStyle("");
- calendarColor.setRenderer(new GridCellRenderer() {
-
- @Override
- public Object render(CalendarWrapper model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store,
- Grid grid) {
-
- final SimplePanel panel = new SimplePanel();
- panel.setPixelSize(14, 14);
- panel.getElement().getStyle().setMarginLeft(3, Unit.PX);
-
- panel.setStyleName("calendar-fullday-event-" + model.getCalendar().getStyle());
- return panel;
- }
- });
-
- selectionModel = new CheckBoxSelectionModel();
-
- final ColumnModel calendarColumnModel = new ColumnModel(Arrays.asList(selectionModel.getColumn(), calendarName, calendarColor));
-
- calendarsStore = new ListStore();
-
- final Grid calendarGrid = new Grid(calendarsStore, calendarColumnModel);
- calendarGrid.setAutoExpandColumn("name");
- calendarGrid.setSelectionModel(selectionModel);
- calendarGrid.addPlugin(selectionModel);
-
- calendarGrid.getView().setForceFit(true);
-
- calendarsPanel.add(calendarGrid);
- return calendarsPanel;
- }
-
- /**
- * Creates the calendars main panel, place holder for the {@link CalendarWidget}.
- *
- * @return The calendars main panel.
- */
- private Component createCalendarsMainPanel() {
-
- calendarView = Panels.content(I18N.CONSTANTS.loading(), "panel-background"); // Temporary title.
-
- // Toolbar
- toolbar = new ToolBar();
-
- // Today button - center the calendar on the current day
- todayButton = Forms.button(I18N.CONSTANTS.today());
- toolbar.add(todayButton);
-
- toolbar.add(new SeparatorToolItem());
-
- // Week button - changes the calendar to display weeks
- weekButton = Forms.button(I18N.CONSTANTS.week());
- toolbar.add(weekButton);
-
- // Week button - changes the calendar to display monthes
- monthButton = Forms.button(I18N.CONSTANTS.month());
- toolbar.add(monthButton);
-
- toolbar.add(new SeparatorToolItem());
-
- // Previous button - move back from one unit of time (week / month)
- previousButton = Forms.button(I18N.CONSTANTS.previous());
- toolbar.add(previousButton);
-
- // Next button - move forward from one unit of time (week / month)
- nextButton = Forms.button(I18N.CONSTANTS.next());
- toolbar.add(nextButton);
-
- toolbar.add(new SeparatorToolItem());
-
- addEventButton = Forms.button(I18N.CONSTANTS.calendarAddEvent());
-
- reminderAddButton = new Button(I18N.CONSTANTS.reminderPoint(), IconImageBundle.ICONS.add());
-
- monitoredPointsAddButton = new Button(I18N.CONSTANTS.monitoredPoint(), IconImageBundle.ICONS.add());
-
- calendarView.setTopComponent(toolbar);
-
- return calendarView;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void initializeCalendarWidget(final CalendarWidget calendarWidget) {
-
- // Defining the first day of the week
- // BUGFIX #653: Contrary to the deprecated DateTimeConstants, firstDayOfTheWeek starts at 0 (and not 1). No substraction is needed.
- final DateTimeFormatInfo constants = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo();
- calendarWidget.setFirstDayOfWeek(constants.firstDayOfTheWeek());
-
- // Retrieving the current calendar header
- calendarView.setHeadingHtml(calendarWidget.getHeading());
-
- // Listening for further calendar header changes
- calendarWidget.setListener(new CalendarWidget.CalendarListener() {
-
- @Override
- public void afterRefresh() {
- calendarView.setHeadingHtml(calendarWidget.getHeading());
- }
- });
-
- calendarView.add(calendarWidget, Layouts.fitData(Margin.DOUBLE_TOP, Margin.DOUBLE_RIGHT, Margin.DOUBLE_BOTTOM, Margin.DOUBLE_LEFT));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setAddEventButtonEnabled(final boolean addEventButtonEnabled) {
-
- if (toolbar.indexOf(addEventButton) != -1) {
- toolbar.remove(addEventButton);
- toolbar.remove(reminderAddButton);
- toolbar.remove(monitoredPointsAddButton);
- }
-
- if (addEventButtonEnabled) {
- toolbar.add(addEventButton);
- toolbar.add(reminderAddButton);
- toolbar.add(monitoredPointsAddButton);
-
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getAddEventButton() {
- return addEventButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getTodayButton() {
- return todayButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getWeekButton() {
- return weekButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getMonthButton() {
- return monthButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getPreviousButton() {
- return previousButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getNextButton() {
- return nextButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getReminderAddButton() {
- return reminderAddButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Button getMonitoredPointsAddButton() {
- return monitoredPointsAddButton;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public AbstractStoreSelectionModel getCalendarsSelectionModel() {
- return selectionModel;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ListStore getCalendarsStore() {
- return calendarsStore;
- }
-
-}
+import org.sigmah.client.i18n.I18N;
+import org.sigmah.client.ui.presenter.calendar.CalendarPresenter;
+import org.sigmah.client.ui.view.base.AbstractView;
+import org.sigmah.client.ui.widget.CalendarWidget;
+import org.sigmah.client.ui.widget.button.Button;
+import org.sigmah.client.ui.widget.form.Forms;
+import org.sigmah.client.ui.widget.layout.Layouts;
+import org.sigmah.client.ui.widget.layout.Layouts.Margin;
+import org.sigmah.client.ui.widget.panel.Panels;
+import org.sigmah.shared.dto.calendar.CalendarWrapper;
+
+import com.extjs.gxt.ui.client.Style.LayoutRegion;
+import com.extjs.gxt.ui.client.Style.Scroll;
+import com.extjs.gxt.ui.client.store.ListStore;
+import com.extjs.gxt.ui.client.widget.Component;
+import com.extjs.gxt.ui.client.widget.ContentPanel;
+import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
+import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
+import com.extjs.gxt.ui.client.widget.grid.ColumnData;
+import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
+import com.extjs.gxt.ui.client.widget.grid.Grid;
+import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
+import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
+import com.extjs.gxt.ui.client.widget.selection.AbstractStoreSelectionModel;
+import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;
+import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.i18n.client.LocaleInfo;
+import com.google.gwt.i18n.shared.DateTimeFormatInfo;
+import com.google.gwt.user.client.ui.SimplePanel;
+import org.sigmah.client.ui.res.icon.IconImageBundle;
+
+/**
+ * Calendar widget presenter.
+ *
+ * @author Raphaël Calabro (rcalabro@ideia.fr) (v1.3)
+ * @author Denis Colliot (dcolliot@ideia.fr) (v2.0)
+ */
+public class CalendarView extends AbstractView implements CalendarPresenter.View {
+
+ private ContentPanel calendarView;
+
+ private ListStore calendarsStore;
+ private CheckBoxSelectionModel selectionModel;
+
+ private ToolBar toolbar;
+ private Button addEventButton;
+ private Button todayButton;
+ private Button weekButton;
+ private Button monthButton;
+ private Button previousButton;
+ private Button nextButton;
+
+ private Button reminderAddButton;
+ private Button monitoredPointsAddButton;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void initialize() {
+
+ // --
+ // Calendars left panel.
+ // --
+ final BorderLayoutData calendarListData = Layouts.borderLayoutData(LayoutRegion.WEST, Layouts.LEFT_COLUMN_WIDTH);
+ calendarListData.setCollapsible(true);
+ add(createCalendarsGridPanel(), calendarListData);
+
+ // --
+ // Calendar center widget.
+ // --
+ add(createCalendarsMainPanel(), Layouts.borderLayoutData(LayoutRegion.CENTER, Margin.LEFT));
+ }
+
+ /**
+ * Creates the calendars panel + grid.
+ *
+ * @return The calendars panel.
+ */
+ private Component createCalendarsGridPanel() {
+
+ // Calendars panel.
+ final ContentPanel calendarsPanel = Panels.content(I18N.CONSTANTS.projectTabCalendar());
+
+ // Calendars grid.
+ final ColumnConfig calendarName = new ColumnConfig("name", I18N.CONSTANTS.name(), 180);
+ final ColumnConfig calendarColor = new ColumnConfig("color", "", 20);
+ calendarColor.setStyle("");
+ calendarColor.setRenderer(new GridCellRenderer() {
+
+ @Override
+ public Object render(CalendarWrapper model, String property, ColumnData config, int rowIndex, int colIndex, ListStore store,
+ Grid grid) {
+
+ final SimplePanel panel = new SimplePanel();
+ panel.setPixelSize(14, 14);
+ panel.getElement().getStyle().setMarginLeft(3, Unit.PX);
+
+ panel.setStyleName("calendar-fullday-event-" + model.getCalendar().getStyle());
+ return panel;
+ }
+ });
+
+ selectionModel = new CheckBoxSelectionModel();
+
+ final ColumnModel calendarColumnModel = new ColumnModel(Arrays.asList(selectionModel.getColumn(), calendarName, calendarColor));
+
+ calendarsStore = new ListStore();
+
+ final Grid calendarGrid = new Grid(calendarsStore, calendarColumnModel);
+ calendarGrid.setAutoExpandColumn("name");
+ calendarGrid.setSelectionModel(selectionModel);
+ calendarGrid.addPlugin(selectionModel);
+
+ calendarGrid.getView().setForceFit(true);
+
+ calendarsPanel.add(calendarGrid);
+ return calendarsPanel;
+ }
+
+ /**
+ * Creates the calendars main panel, place holder for the
+ * {@link CalendarWidget}.
+ *
+ * @return The calendars main panel.
+ */
+ private Component createCalendarsMainPanel() {
+
+ calendarView = Panels.content(I18N.CONSTANTS.loading(), "panel-background"); // Temporary title.
+
+ // Toolbar
+ toolbar = new ToolBar();
+
+ // Today button - center the calendar on the current day
+ todayButton = Forms.button(I18N.CONSTANTS.today());
+ toolbar.add(todayButton);
+
+ toolbar.add(new SeparatorToolItem());
+
+ // Week button - changes the calendar to display weeks
+ weekButton = Forms.button(I18N.CONSTANTS.week());
+ toolbar.add(weekButton);
+
+ // Week button - changes the calendar to display monthes
+ monthButton = Forms.button(I18N.CONSTANTS.month());
+ toolbar.add(monthButton);
+
+ toolbar.add(new SeparatorToolItem());
+
+ // Previous button - move back from one unit of time (week / month)
+ previousButton = Forms.button(I18N.CONSTANTS.previous());
+ toolbar.add(previousButton);
+
+ // Next button - move forward from one unit of time (week / month)
+ nextButton = Forms.button(I18N.CONSTANTS.next());
+ toolbar.add(nextButton);
+
+ toolbar.add(new SeparatorToolItem());
+
+ addEventButton = Forms.button(I18N.CONSTANTS.calendarAddEvent(), IconImageBundle.ICONS.add());
+ reminderAddButton = new Button(I18N.CONSTANTS.reminderPoint(), IconImageBundle.ICONS.add());
+ monitoredPointsAddButton = new Button(I18N.CONSTANTS.monitoredPoint(), IconImageBundle.ICONS.add());
+
+ calendarView.setTopComponent(toolbar);
+
+ return calendarView;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void initializeCalendarWidget(final CalendarWidget calendarWidget) {
+
+ // Defining the first day of the week
+ // BUGFIX #653: Contrary to the deprecated DateTimeConstants, firstDayOfTheWeek starts at 0 (and not 1). No substraction is needed.
+ final DateTimeFormatInfo constants = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo();
+ calendarWidget.setFirstDayOfWeek(constants.firstDayOfTheWeek());
+
+ // Retrieving the current calendar header
+ calendarView.setHeadingHtml(calendarWidget.getHeading());
+
+ // Listening for further calendar header changes
+ calendarWidget.setListener(new CalendarWidget.CalendarListener() {
+
+ @Override
+ public void afterRefresh() {
+ calendarView.setHeadingHtml(calendarWidget.getHeading());
+ }
+ });
+ calendarView.setScrollMode(Scroll.AUTOY);//ss
+ calendarView.add(calendarWidget, Layouts.fitData(Margin.DOUBLE_TOP, Margin.DOUBLE_RIGHT, Margin.DOUBLE_BOTTOM, Margin.DOUBLE_LEFT));
+
+ calendarView.add(calendarWidget, Layouts.fitData(Margin.DOUBLE_TOP, Margin.DOUBLE_RIGHT, Margin.DOUBLE_BOTTOM, Margin.DOUBLE_LEFT));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setAddEventButtonEnabled(final boolean addEventButtonEnabled) {
+
+ if (toolbar.indexOf(addEventButton) != -1) {
+ toolbar.remove(addEventButton);
+ toolbar.remove(reminderAddButton);
+ toolbar.remove(monitoredPointsAddButton);
+ }
+
+ if (addEventButtonEnabled) {
+ toolbar.add(addEventButton);
+ toolbar.add(reminderAddButton);
+ toolbar.add(monitoredPointsAddButton);
+
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getAddEventButton() {
+ return addEventButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getTodayButton() {
+ return todayButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getWeekButton() {
+ return weekButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getMonthButton() {
+ return monthButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getPreviousButton() {
+ return previousButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getNextButton() {
+ return nextButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getReminderAddButton() {
+ return reminderAddButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Button getMonitoredPointsAddButton() {
+ return monitoredPointsAddButton;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public AbstractStoreSelectionModel getCalendarsSelectionModel() {
+ return selectionModel;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ListStore getCalendarsStore() {
+ return calendarsStore;
+ }
+
+}
diff --git a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java
index b223a6031..c4761e9ce 100644
--- a/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java
+++ b/src/main/java/org/sigmah/client/ui/widget/CalendarWidget.java
@@ -21,7 +21,6 @@
* .
* #L%
*/
-
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
@@ -44,6 +43,7 @@
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
@@ -54,425 +54,539 @@
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
+import com.google.gwt.user.client.ui.Widget;
+import org.sigmah.client.util.FormattingUtil;
/**
* This widget displays a calendar.
- *
+ *
* @author Raphaël Calabro (rcalabro@ideia.fr)
*/
@SuppressWarnings("deprecation")
public class CalendarWidget extends Composite {
- public static final int CELL_DEFAULT_WIDTH = 150;
- public static final int CELL_DEFAULT_HEIGHT = 80;
-
- public interface CalendarListener {
-
- void afterRefresh();
-
- }
-
- public interface Delegate {
-
- void edit(Event event, CalendarWidget calendarWidget);
-
- void delete(Event event, CalendarWidget calendarWidget);
-
- }
-
- /**
- * Types of displays availables for a calendar.
- *
- * @author rca
- */
- public static enum DisplayMode {
- DAY(1, 1) {
-
- @Override
- public Date getStartDate(Date date, int firstDay) {
- return new Date(date.getYear(), date.getMonth(), date.getDate());
- }
-
- @Override
- public void nextDate(Date currentDate) {
- currentDate.setDate(currentDate.getDate() + 1);
- }
-
- @Override
- public void previousDate(Date currentDate) {
- currentDate.setDate(currentDate.getDate() - 1);
- }
-
- @Override
- public void firstDay(Date currentDate, Date today, int firstDay) {
- currentDate.setYear(today.getYear());
- currentDate.setMonth(today.getMonth());
- currentDate.setDate(today.getDate());
- }
-
- @Override
- public String getStyleName() {
- return "calendar-day";
- }
- },
- WEEK(7, 1) {
-
- @Override
- public Date getStartDate(Date date, int firstDay) {
- return getFirstDateOfWeek(date, firstDay);
- }
-
- @Override
- public void nextDate(Date currentDate) {
- currentDate.setDate(currentDate.getDate() + 7);
- }
-
- @Override
- public void previousDate(Date currentDate) {
- currentDate.setDate(currentDate.getDate() - 7);
- }
-
- @Override
- public void firstDay(Date currentDate, Date today, int firstDay) {
- int decal = (today.getDay() + 7 - firstDay) % 7;
- currentDate.setYear(today.getYear());
- currentDate.setMonth(today.getMonth());
- currentDate.setDate(today.getDate() - decal);
- final Date date = getFirstDateOfWeek(today, firstDay);
- currentDate.setTime(date.getTime());
- }
-
- @Override
- public String getStyleName() {
- return "calendar-week";
- }
- },
- MONTH(7, 6) {
-
- @Override
- public Date getStartDate(Date date, int firstDay) {
- Date firstDayOfMonth = new Date(date.getYear(), date.getMonth(), 1);
- return getFirstDateOfWeek(firstDayOfMonth, firstDay);
- }
-
- @Override
- public void nextDate(Date currentDate) {
- currentDate.setMonth(currentDate.getMonth() + 1);
- }
-
- @Override
- public void previousDate(Date currentDate) {
- currentDate.setMonth(currentDate.getMonth() - 1);
- }
-
- @Override
- public void firstDay(Date currentDate, Date today, int firstDay) {
- currentDate.setYear(today.getYear());
- currentDate.setMonth(today.getMonth());
- currentDate.setDate(1);
- }
-
- @Override
- public String getStyleName() {
- return "calendar-month";
- }
- };
-
- private int columns;
- private int rows;
-
- private DisplayMode(int columns, int rows) {
- this.columns = columns;
- this.rows = rows;
- }
-
- public int getRows() {
- return rows;
- }
-
- public int getColumns() {
- return columns;
- }
-
- public abstract Date getStartDate(Date date, int firstDay);
-
- public abstract void nextDate(Date currentDate);
-
- public abstract void previousDate(Date currentDate);
-
- public abstract void firstDay(Date currentDate, Date today, int firstDay);
-
- public abstract String getStyleName();
- }
-
- public final static int NO_HEADERS = 0;
- public final static int COLUMN_HEADERS = 1;
- public final static int ALL_HEADERS = 2;
-
- private final static int UNDEFINED = -1;
- private final static int EVENT_HEIGHT = 16;
- private int eventLimit = UNDEFINED;
-
- private int firstDayOfWeek;
- private DisplayMode displayMode = DisplayMode.MONTH;
- private int displayHeaders = ALL_HEADERS;
- private boolean displayWeekNumber = true;
-
- private List calendars;
-
- private Date today;
- private Date startDate;
-
- private DateTimeFormat titleFormatter = DateTimeFormat.getFormat("MMMM y");
- private DateTimeFormat headerFormatter = DateTimeFormat.getFormat("EEEE");
- private DateTimeFormat dayFormatter = DateTimeFormat.getFormat("d");
- private DateTimeFormat hourFormatter = DateTimeFormat.getFormat("HH:mm");
-
- private CalendarListener listener;
- private Delegate delegate;
-
- private final Authentication authentication;
-
- public CalendarWidget(int displayHeaders, boolean displayWeekNumber, Authentication authentication) {
- this.calendars = new ArrayList();
- this.displayHeaders = displayHeaders;
- this.displayWeekNumber = displayWeekNumber;
- this.authentication = authentication;
-
- // final SimplePanel container;
-
- final FlexTable grid = new FlexTable();
- grid.addStyleName("calendar");
- grid.addStyleName(displayMode.getStyleName());
-
- initWidget(grid);
-
- final Date now = new Date();
- today = new Date(now.getYear(), now.getMonth(), now.getDate());
- startDate = new Date(0, 0, 0);
-
- today();
- }
-
- public void setDelegate(Delegate delegate) {
- this.delegate = delegate;
- }
-
- public void setListener(CalendarListener listener) {
- this.listener = listener;
- }
-
- public void next() {
- displayMode.nextDate(startDate);
- refresh();
- }
-
- public void previous() {
- displayMode.previousDate(startDate);
- refresh();
- }
-
- public final void today() {
- displayMode.firstDay(startDate, today, firstDayOfWeek);
- refresh();
- }
-
- /**
- * Retrieves the current start date of the calendar.
- *
- * @return the current start date of the calendar.
- */
- public Date getStartDate() {
- return startDate;
- }
-
- public void addCalendar(Calendar calendar) {
- calendars.add(calendar);
- refresh();
- }
-
- public List getCalendars() {
- return calendars;
- }
-
- public void setCalendars(List calendars) {
- this.calendars = calendars;
- refresh();
- }
-
- /**
- * Defines the formatter used to display the title of the calendar.
- *
- * The default format is "MonthName
FullYear
" (pattern : "N y").
- *
- * @param titleFormatter
- * The formatter to use to display the title of the calendar.
- */
- public void setTitleFormatter(DateTimeFormat titleFormatter) {
- this.titleFormatter = titleFormatter;
- refresh();
- }
-
- /**
- * Defines the formatter used to display the title of each column.
- *
- * The default format is "WeekName
" (pattern : "E").
- *
- * @param headerFormatter
- * The formatter to use to display the title of each column.
- */
- public void setHeaderFormatter(DateTimeFormat headerFormatter) {
- this.headerFormatter = headerFormatter;
- refresh();
- }
-
- /**
- * Defines the formatter used to display the title of each cell.
- *
- * The default format is "DayNumber
" (pattern : "d").
- *
- * @param dayFormatter
- * The formatter to use to display the title of each cell.
- */
- public void setDayFormatter(DateTimeFormat dayFormatter) {
- this.dayFormatter = dayFormatter;
- refresh();
- }
-
- /**
- * Defines the display mode of the calendar and perform a redraw.
- *
- * @param displayMode
- * Style of the calendar (day, week or month).
- * @see CalendarWidget.DisplayMode
- */
- public void setDisplayMode(DisplayMode displayMode) {
- final FlexTable grid = (FlexTable) getWidget();
-
- clear();
-
- // Resetting the CSS style
- grid.removeStyleName(this.displayMode.getStyleName());
-
- this.displayMode = displayMode;
-
- // Applying the CSS style associated with the new display mode
- grid.addStyleName(displayMode.getStyleName());
-
- refresh();
- }
-
- /**
- * Defines the first day of the week and refresh the calendar.
- *
- * @param firstDayOfWeek
- * The first day of the week as an int (Sunday = 0, Saturday = 6)
- */
- public void setFirstDayOfWeek(int firstDayOfWeek) {
- this.firstDayOfWeek = firstDayOfWeek;
- refresh();
- }
-
- public int getDisplayHeaders() {
- return displayHeaders;
- }
-
- public void setDisplayHeaders(int displayHeaders) {
- clear();
- this.displayHeaders = displayHeaders;
- refresh();
- }
-
- public boolean isDisplayWeekNumber() {
- return displayWeekNumber;
- }
-
- public void setDisplayWeekNumber(boolean displayWeekNumber) {
- clear();
- this.displayWeekNumber = displayWeekNumber;
- refresh();
- }
-
- /**
- * Removes all rows. Must be when the structure of the calendar has been changed (display mode)
- */
- private void clear() {
- final FlexTable grid = (FlexTable) getWidget();
- grid.clear();
- grid.removeAllRows();
- }
-
- /**
- * @param date1
- * @param date2
- * @return boolean indicating if date1 and date2 are on the same day
- */
- public static boolean isSameDay(Date date1, Date date2) {
- DateTimeFormat fmt = DateTimeFormat.getFormat("yyyyMMdd");
- return fmt.format(date1).equals(fmt.format(date2));
- }
-
- /**
- * Normalizes the given {@code calendar}'s events map (needed particularly when there is a timezone difference between
- * the client and the server).
- *
- * @param calendar
- * The calendar instance.
- * @return The map with each event with the right key.
- */
- public static Map> normalize(final Calendar calendar) {
-
- final Map> eventMap = calendar.getEvents();
- final Map> eventMapNormalized = new HashMap>();
-
- boolean isActivityCalendar = false;
- if (calendar.getIdentifier() instanceof ActivityCalendarIdentifier) {
- isActivityCalendar = true;
- }
-
- for (final Date key : eventMap.keySet()) {
- for (final Event event : eventMap.get(key)) {
- Date normalizedKeyDate = new Date(key.getYear(), key.getMonth(), key.getDate());
-
- // Activities events have different startDate from the key date
- // They shouldn't be placed in their startDate list
- if (!isSameDay(normalizedKeyDate, event.getDtstart()) && !isActivityCalendar) {
- normalizedKeyDate = new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate());
- }
-
- if (eventMapNormalized.get(normalizedKeyDate) == null) {
- eventMapNormalized.put(normalizedKeyDate, new ArrayList());
- }
- eventMapNormalized.get(normalizedKeyDate).add(event);
- }
- }
-
- return eventMapNormalized;
- }
-
- /**
- * Calculates the number of events that can be displayed in a cell.
- */
- public void calibrateCalendar() {
- final FlexTable grid = (FlexTable) getWidget();
-
- final Element row = grid.getRowFormatter().getElement(displayHeaders);
- row.setId("calendar-row-calibration");
-
- final Element cell = grid.getCellFormatter().getElement(displayHeaders, displayWeekNumber ? 1 : 0);
- cell.setId("calendar-cell-calibration");
-
- eventLimit = (getCellHeight(CELL_DEFAULT_HEIGHT) / EVENT_HEIGHT) - 2;
- if (eventLimit < 0)
- eventLimit = 0;
- }
-
- /**
- * Calculates the height of the cell identified by "calendar-cell-calibration".
- *
- * @return height of a cell.
- */
- private native int getCellHeight(int defaultHeight) /*-{
+ public static final int CELL_DEFAULT_WIDTH = 150;
+ public static final int CELL_DEFAULT_HEIGHT = 80;
+
+ /**
+ * Multiple calculated ("cached") values reused during laying out
+ * the month view elements.
+ */
+ private static final int DAYS_IN_A_WEEK = 7;
+ private int calculatedWeekDayHeaderHeight;
+ private int calculatedDayHeaderHeight;
+ /**
+ * Height of each Cell (day), including the day's header.
+ */
+ private float calculatedCellOffsetHeight;
+
+ /**
+ * Height of each Cell (day), excluding the day's header.
+ */
+ private float calculatedCellHeight;
+
+ public interface CalendarListener {
+
+ void afterRefresh();
+
+ }
+
+ public interface Delegate {
+
+ void edit(Event event, CalendarWidget calendarWidget);
+
+ void delete(Event event, CalendarWidget calendarWidget);
+
+ void deleteChain(Event event, CalendarWidget calendarWidget);
+
+ }
+
+ /**
+ * Types of displays availables for a calendar.
+ *
+ * @author rca
+ */
+ public static enum DisplayMode {
+ DAY(1, 1) {
+
+ @Override
+ public Date getStartDate(Date date, int firstDay) {
+ return new Date(date.getYear(), date.getMonth(), date.getDate());
+ }
+
+ @Override
+ public void nextDate(Date currentDate) {
+ currentDate.setDate(currentDate.getDate() + 1);
+ }
+
+ @Override
+ public void previousDate(Date currentDate) {
+ currentDate.setDate(currentDate.getDate() - 1);
+ }
+
+ @Override
+ public void firstDay(Date currentDate, Date today, int firstDay) {
+ currentDate.setYear(today.getYear());
+ currentDate.setMonth(today.getMonth());
+ currentDate.setDate(today.getDate());
+ }
+
+ @Override
+ public String getStyleName() {
+ return "calendar-day";
+ }
+ },
+ WEEK(DAYS_IN_A_WEEK, 1) {
+
+ @Override
+ public Date getStartDate(Date date, int firstDay) {
+ return getFirstDateOfWeek(date, firstDay);
+ }
+
+ @Override
+ public void nextDate(Date currentDate) {
+ currentDate.setDate(currentDate.getDate() + DAYS_IN_A_WEEK);
+ }
+
+ @Override
+ public void previousDate(Date currentDate) {
+ currentDate.setDate(currentDate.getDate() - DAYS_IN_A_WEEK);
+ }
+
+ @Override
+ public void firstDay(Date currentDate, Date today, int firstDay) {
+ int decal = (today.getDay() + DAYS_IN_A_WEEK - firstDay) % DAYS_IN_A_WEEK;
+ currentDate.setYear(today.getYear());
+ currentDate.setMonth(today.getMonth());
+ currentDate.setDate(today.getDate() - decal);
+ final Date date = getFirstDateOfWeek(today, firstDay);
+ currentDate.setTime(date.getTime());
+ }
+
+ @Override
+ public String getStyleName() {
+ return "calendar-week";
+ }
+ },
+ MONTH(7, 6) {
+
+ @Override
+ public Date getStartDate(Date date, int firstDay) {
+ Date firstDayOfMonth = new Date(date.getYear(), date.getMonth(), 1);
+ return getFirstDateOfWeek(firstDayOfMonth, firstDay);
+ }
+
+ @Override
+ public void nextDate(Date currentDate) {
+ currentDate.setMonth(currentDate.getMonth() + 1);
+ }
+
+ @Override
+ public void previousDate(Date currentDate) {
+ currentDate.setMonth(currentDate.getMonth() - 1);
+ }
+
+ @Override
+ public void firstDay(Date currentDate, Date today, int firstDay) {
+ currentDate.setYear(today.getYear());
+ currentDate.setMonth(today.getMonth());
+ currentDate.setDate(1);
+ }
+
+ @Override
+ public String getStyleName() {
+ return "calendar-month";
+ }
+ };
+
+ private int columns;
+ private int rows;
+
+ private DisplayMode(int columns, int rows) {
+ this.columns = columns;
+ this.rows = rows;
+ }
+
+ public int getRows() {
+ return rows;
+ }
+
+ public int getColumns() {
+ return columns;
+ }
+
+ public abstract Date getStartDate(Date date, int firstDay);
+
+ public abstract void nextDate(Date currentDate);
+
+ public abstract void previousDate(Date currentDate);
+
+ public abstract void firstDay(Date currentDate, Date today, int firstDay);
+
+ public abstract String getStyleName();
+ }
+
+ public final static int NO_HEADERS = 0;
+ public final static int COLUMN_HEADERS = 1;
+ public final static int ALL_HEADERS = 2;
+
+ private final static int UNDEFINED = -1;
+ private final static int EVENT_HEIGHT = 16;
+ private int eventLimit = UNDEFINED;
+
+ private int firstDayOfWeek;
+ private DisplayMode displayMode = DisplayMode.MONTH;
+ private int displayHeaders = ALL_HEADERS;
+ private boolean displayWeekNumber = true;
+
+ private List calendars;
+
+ private Date today;
+ private Date startDate;
+
+ private DateTimeFormat titleFormatter = DateTimeFormat.getFormat("MMMM y");
+ private DateTimeFormat headerFormatter = DateTimeFormat.getFormat("EEEE");
+ private DateTimeFormat dayFormatter = DateTimeFormat.getFormat("d");
+ private DateTimeFormat hourFormatter = DateTimeFormat.getFormat("HH:mm");
+
+ private CalendarListener listener;
+ private Delegate delegate;
+
+ private final Authentication authentication;
+
+ public CalendarWidget(int displayHeaders, boolean displayWeekNumber, Authentication authentication) {
+ this.calendars = new ArrayList();
+ this.displayHeaders = displayHeaders;
+ this.displayWeekNumber = displayWeekNumber;
+ this.authentication = authentication;
+
+ // final SimplePanel container;
+ final FlexTable grid = new FlexTable();
+// getColumnFormatter().getElement( column ).setAttribute( "width",
+// grid.getFlexCellFormatter().getElement(0, 0)
+ grid.addStyleName("calendar");
+ grid.addStyleName(displayMode.getStyleName());
+// VerticalPanel dialogContents = new VerticalPanel();
+// dialogContents.add(grid);
+// initWidget(dialogContents);
+ initWidget(grid);
+
+ final Date now = new Date();
+ today = new Date(now.getYear(), now.getMonth(), now.getDate());
+ startDate = new Date(0, 0, 0);
+
+ today();
+ }
+
+ public void setDelegate(Delegate delegate) {
+ this.delegate = delegate;
+ }
+
+ public void setListener(CalendarListener listener) {
+ this.listener = listener;
+ }
+
+ public void next() {
+ displayMode.nextDate(startDate);
+ refresh();
+ }
+
+ public void previous() {
+ displayMode.previousDate(startDate);
+ refresh();
+ }
+
+ public final void today() {
+ displayMode.firstDay(startDate, today, firstDayOfWeek);
+ refresh();
+ }
+
+ /**
+ * Retrieves the current start date of the calendar.
+ *
+ * @return the current start date of the calendar.
+ */
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void addCalendar(Calendar calendar) {
+ calendars.add(calendar);
+ refresh();
+ }
+
+ public List getCalendars() {
+ return calendars;
+ }
+
+ public void setCalendars(List calendars) {
+ // this.calendars = calendars;
+// Window.alert("SET setCalendars");
+// for (Calendar calendar : calendars) {
+// if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) {
+// if (calendar.getEvents() != null) {
+// //SSS final Map> eventMap = normalize(calendar.getEvents());
+// final Map> eventMap = normalizeHourEvents(calendar.getEvents());
+// calendar.setEvents(eventMap);
+// }
+// }
+// }
+ this.calendars = calendars;
+ refresh();
+ }
+
+ /**
+ * Defines the formatter used to display the title of the calendar.
+ *
+ * The default format is "MonthName
FullYear
"
+ * (pattern : "N y").
+ *
+ * @param titleFormatter The formatter to use to display the title of the
+ * calendar.
+ */
+ public void setTitleFormatter(DateTimeFormat titleFormatter) {
+ this.titleFormatter = titleFormatter;
+ refresh();
+ }
+
+ /**
+ * Defines the formatter used to display the title of each column.
+ *
+ * The default format is "WeekName
" (pattern : "E").
+ *
+ * @param headerFormatter The formatter to use to display the title of each
+ * column.
+ */
+ public void setHeaderFormatter(DateTimeFormat headerFormatter) {
+ this.headerFormatter = headerFormatter;
+ refresh();
+ }
+
+ /**
+ * Defines the formatter used to display the title of each cell.
+ *
+ * The default format is "DayNumber
" (pattern : "d").
+ *
+ * @param dayFormatter The formatter to use to display the title of each
+ * cell.
+ */
+ public void setDayFormatter(DateTimeFormat dayFormatter) {
+ this.dayFormatter = dayFormatter;
+ refresh();
+ }
+
+ /**
+ * Defines the display mode of the calendar and perform a redraw.
+ *
+ * @param displayMode Style of the calendar (day, week or month).
+ * @see CalendarWidget.DisplayMode
+ */
+ public void setDisplayMode(DisplayMode displayMode) {
+ final FlexTable grid = (FlexTable) getWidget();
+
+ clear();
+
+ // Resetting the CSS style
+ grid.removeStyleName(this.displayMode.getStyleName());
+
+ this.displayMode = displayMode;
+
+ // Applying the CSS style associated with the new display mode
+ grid.addStyleName(displayMode.getStyleName());
+ refresh();
+ }
+
+ /**
+ * Defines the first day of the week and refresh the calendar.
+ *
+ * @param firstDayOfWeek The first day of the week as an int (Sunday = 0,
+ * Saturday = 6)
+ */
+ public void setFirstDayOfWeek(int firstDayOfWeek) {
+ this.firstDayOfWeek = firstDayOfWeek;
+ refresh();
+ }
+
+ public int getDisplayHeaders() {
+ return displayHeaders;
+ }
+
+ public void setDisplayHeaders(int displayHeaders) {
+ clear();
+ this.displayHeaders = displayHeaders;
+ refresh();
+ }
+
+ public boolean isDisplayWeekNumber() {
+ return displayWeekNumber;
+ }
+
+ public void setDisplayWeekNumber(boolean displayWeekNumber) {
+ clear();
+ this.displayWeekNumber = displayWeekNumber;
+ refresh();
+ }
+
+ /**
+ * Removes all rows. Must be when the structure of the calendar has been
+ * changed (display mode)
+ */
+ private void clear() {
+ final FlexTable grid = (FlexTable) getWidget();
+ grid.clear();
+ grid.removeAllRows();
+ }
+
+ /**
+ * @param date1
+ * @param date2
+ * @return boolean indicating if date1 and date2 are on the same day
+ */
+ public static boolean isSameDay(Date date1, Date date2) {
+ DateTimeFormat fmt = DateTimeFormat.getFormat("yyyyMMdd");
+ return fmt.format(date1).equals(fmt.format(date2));
+ }
+
+ /**
+ * Normalizes the given {@code calendar}'s events map (needed particularly
+ * when there is a timezone difference between the client and the server).
+ *
+ * @param calendar The calendar instance.
+ * @return The map with each event with the right key.
+ */
+ //public static Map> normalize(final Calendar calendar) {
+ public static Map> normalize(final Map> eventMap) {
+
+// final Map> eventMap = calendar.getEvents();
+ final Map> eventMapNormalized = new HashMap>();
+
+// boolean isActivityCalendar = false;
+// if (calendar.getIdentifier() instanceof ActivityCalendarIdentifier) {
+// isActivityCalendar = true;
+// }
+ for (final Date key : eventMap.keySet()) {
+ for (final Event event : eventMap.get(key)) {
+ Date normalizedKeyDate = new Date(key.getYear(), key.getMonth(), key.getDate());
+
+ // Activities events have different startDate from the key date
+ // They shouldn't be placed in their startDate list
+ //if (!isSameDay(normalizedKeyDate, event.getDtstart()) && !isActivityCalendar) {
+ if (!isSameDay(normalizedKeyDate, event.getDtstart())) {
+ normalizedKeyDate = new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate());
+ }
+
+ if (eventMapNormalized.get(normalizedKeyDate) == null) {
+ eventMapNormalized.put(normalizedKeyDate, new ArrayList());
+ }
+ eventMapNormalized.get(normalizedKeyDate).add(event);
+ }
+ }
+
+ return eventMapNormalized;
+ }
+
+ public static Map> normalizeHourEvents(final Map> eventMap) {
+
+ final Map> hourEventMapNormalized = new HashMap>();
+
+ for (final Date key : eventMap.keySet()) {
+ for (final Event event : eventMap.get(key)) {
+ Date normalizedKeyDate = new Date(key.getYear(), key.getMonth(), key.getDate());
+ if (!isSameDay(event.getDtstart(), event.getDtend())) {
+ // Window.alert("! isSameDay" + event.getSummary());
+ // if (event.getDtstart() != event.getDtend()) {
+ //1
+ int daysdiff = calculateEventDurationInDays(event);
+ for (int i = 0; i < daysdiff; i++) {
+ long StartTime = event.getDtstart().getTime() + (24 * 60 * 60 * 1000) * i;
+ long EndTime = event.getDtstart().getTime() + (24 * 60 * 60 * 1000) * i;
+
+ Date StartDate = new Date(StartTime);
+
+ Date EndDate = new Date(EndTime);
+ EndDate.setHours(event.getDtend().getHours());
+ EndDate.setMinutes(event.getDtend().getMinutes());
+
+ Event theNewEv = new Event();
+ theNewEv.setDtstart(StartDate);
+ theNewEv.setDtend(EndDate);
+// theNewEv.setIdentifier(event.getIdentifier());
+// theNewEv.setReferenceId(event.getReferenceId());
+// theNewEv.setParent(event.getParent());
+ theNewEv.setSummary(event.getSummary());// + "-S-" + i);
+ theNewEv.setDescription(event.getDescription());// + "-D-" + i);
+// theNewEv.setEventType(event.getEventType());
+ ////////////
+ if (!isSameDay(normalizedKeyDate, theNewEv.getDtstart())) {
+ normalizedKeyDate = new Date(theNewEv.getDtstart().getYear(), theNewEv.getDtstart().getMonth(), theNewEv.getDtstart().getDate());
+ }
+
+ if (hourEventMapNormalized.get(normalizedKeyDate) == null) {
+ hourEventMapNormalized.put(normalizedKeyDate, new ArrayList());
+ }
+ event.setSummary(theNewEv.getSummary());
+ event.setDescription(theNewEv.getDescription());
+ if (!hourEventMapNormalized.get(normalizedKeyDate).contains(event)) {
+ hourEventMapNormalized.get(normalizedKeyDate).add(event);
+ }
+ // -------------
+// if (!isSameDay(normalizedKeyDate, theNewEv.getDtstart())) {
+// normalizedKeyDate = new Date(theNewEv.getDtstart().getYear(), theNewEv.getDtstart().getMonth(), theNewEv.getDtstart().getDate());
+// }
+//
+// if (hourEventMapNormalized.get(normalizedKeyDate) == null) {
+// hourEventMapNormalized.put(normalizedKeyDate, new ArrayList());
+// }
+// hourEventMapNormalized.get(normalizedKeyDate).add(theNewEv);
+
+ ///////
+ }
+ } else {
+ // Window.alert("THE SameDay " + event.getSummary());
+ if (!isSameDay(normalizedKeyDate, event.getDtstart())) {
+ normalizedKeyDate = new Date(event.getDtstart().getYear(), event.getDtstart().getMonth(), event.getDtstart().getDate());
+ }
+
+ if (hourEventMapNormalized.get(normalizedKeyDate) == null) {
+ hourEventMapNormalized.put(normalizedKeyDate, new ArrayList());
+ }
+ if (!hourEventMapNormalized.get(normalizedKeyDate).contains(event)) {
+ hourEventMapNormalized.get(normalizedKeyDate).add(event);
+ }
+ }
+ }
+ }
+
+ return hourEventMapNormalized;
+ }
+
+ /**
+ * Calculates the number of events that can be displayed in a cell.
+ */
+ public void calibrateCalendar() {
+ final FlexTable grid = (FlexTable) getWidget();
+
+ final Element row = grid.getRowFormatter().getElement(displayHeaders);
+ row.setId("calendar-row-calibration");
+
+ final Element cell = grid.getCellFormatter().getElement(displayHeaders, displayWeekNumber ? 1 : 0);
+ cell.setId("calendar-cell-calibration");
+//ss
+// cell.setPropertyString(DEBUG_ID_PREFIX, DEBUG_ID_PREFIX);setAttribute("hight", "40px");
+ eventLimit = (getCellHeight(CELL_DEFAULT_HEIGHT) / EVENT_HEIGHT) - 2;
+ if (eventLimit < 0) {
+ eventLimit = 0;
+ }
+
+ }
+
+ /**
+ * Calculates the height of the cell identified by
+ * "calendar-cell-calibration".
+ *
+ * @return height of a cell.
+ */
+ private native int getCellHeight(int defaultHeight) /*-{
var height = 0;
if (!$wnd.getComputedStyle)
@@ -486,12 +600,13 @@ private native int getCellHeight(int defaultHeight) /*-{
return height;
}-*/;
- /**
- * Calculates the width of the cell identified by "calendar-cell-calibration".
- *
- * @return width of a cell.
- */
- private native int getCellWidth(int defaultWidth) /*-{
+ /**
+ * Calculates the width of the cell identified by
+ * "calendar-cell-calibration".
+ *
+ * @return width of a cell.
+ */
+ private native int getCellWidth(int defaultWidth) /*-{
var width = 0;
if (!$wnd.getComputedStyle)
@@ -505,353 +620,1194 @@ private native int getCellWidth(int defaultWidth) /*-{
return width;
}-*/;
- /**
- * Retrieves the current heading of the calendar.
- *
- * @return The heading value.
- */
- public String getHeading() {
- final String title = titleFormatter.format(startDate);
- return Character.toUpperCase(title.charAt(0)) + title.substring(1);
- }
-
- /**
- * Render the calendar.
- */
- public void refresh() {
- drawEmptyCells();
-
- if (isAttached()) {
- calibrateCalendar();
- drawEvents();
- }
- if (listener != null)
- listener.afterRefresh();
- }
-
- /**
- * Render the whole calendar but do not render the events.
- */
- public void drawEmptyCells() {
- final FlexTable grid = (FlexTable) getWidget();
-
- final int rows = displayMode.getRows() + displayHeaders;
- final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0);
-
- Date date = displayMode.getStartDate(startDate, firstDayOfWeek);
-
- // Column headers
- if (displayHeaders != NO_HEADERS) {
- if (displayHeaders == ALL_HEADERS) {
- // Header of the calendar
- final Label calendarHeader = new Label(getHeading());
- calendarHeader.addStyleName("calendar-header");
- grid.setWidget(0, 0, calendarHeader);
- grid.getFlexCellFormatter().setColSpan(0, 0, columns + (displayWeekNumber ? 1 : 0));
- }
-
- final Date currentHeader = new Date(date.getTime());
- for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) {
- final Label columnHeader = new Label(headerFormatter.format(currentHeader));
- columnHeader.addStyleName("calendar-column-header");
- grid.setWidget(displayHeaders == ALL_HEADERS ? 1 : 0, x, columnHeader);
-
- currentHeader.setDate(currentHeader.getDate() + 1);
- }
- }
-
- int currentMonth = startDate.getMonth();
- for (int y = displayHeaders; y < rows; y++) {
- if (displayWeekNumber) {
- grid.getCellFormatter().addStyleName(y, 0, "calendar-row-header");
- grid.setText(y, 0, Integer.toString(getWeekNumber(date, firstDayOfWeek)));
- }
-
- for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) {
- drawCell(y, x, date, currentMonth);
- date.setDate(date.getDate() + 1);
- }
- }
- }
-
- /**
- * Render the events for every cells.
- */
- public void drawEvents() {
- final int rows = displayMode.getRows() + displayHeaders;
- final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0);
-
- Date date = displayMode.getStartDate(startDate, firstDayOfWeek);
-
- for (int y = displayHeaders; y < rows; y++) {
- for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) {
- drawEvents(y, x, date);
- date.setDate(date.getDate() + 1);
- }
- }
- }
-
- /**
- * Render the cell located at column
, row
- *
- * @param row
- * @param column
- * @param date
- * @param currentMonth
- */
- private void drawCell(int row, int column, Date date, int currentMonth) {
- final Label header = new Label(dayFormatter.format(date));
- header.addStyleName("calendar-cell-header");
-
- final FlexTable grid = (FlexTable) getWidget();
-
- grid.getCellFormatter().setStyleName(row, column, "calendar-cell");
-
- FlowPanel cell = (FlowPanel) grid.getWidget(row, column);
- if (cell == null) {
- // New cell
- cell = new FlowPanel();
- cell.setWidth("100%");
-
- grid.setWidget(row, column, cell);
-
- } else {
- // Reusing an existing cell
- cell.clear();
- }
-
- if (currentMonth != date.getMonth())
- grid.getCellFormatter().addStyleName(row, column, "calendar-cell-other-month");
- if (date.equals(today))
- grid.getCellFormatter().addStyleName(row, column, "calendar-cell-today");
-
- cell.add(header);
- }
-
- /**
- * Display the events for the cell located at column
, row
- *
- * @param row
- * @param column
- * @param date
- * @param currentMonth
- */
- private void drawEvents(int row, int column, final Date date) {
- final FlexTable grid = (FlexTable) getWidget();
-
- // final VerticalPanel cell = (VerticalPanel) grid.getWidget(row,
- // column);
- final FlowPanel cell = (FlowPanel) grid.getWidget(row, column);
-
- if (cell == null)
- throw new NullPointerException("The specified cell (" + row + ',' + column + ") doesn't exist.");
-
- // Displaying events
- final TreeSet sortedEvents = new TreeSet(new Comparator() {
-
- @Override
- public int compare(Event o1, Event o2) {
- int compare = 0;
-
- if (o1 == null && o2 == null)
- return 0;
- else if (o2 == null)
- return 1;
- else if (o1 == null)
- return -1;
-
- if (compare == 0 && o1.getDtstart() != null && o2.getDtstart() != null) {
- long o1Start = o1.getDtstart().getTime();
- long o2Start = o2.getDtstart().getTime();
-
- if (o1Start < o2Start)
- compare = -1;
- else if (o1Start > o2Start)
- compare = 1;
- }
-
- if (compare == 0 && o1.getSummary() != null && o2.getSummary() != null)
- compare = o1.getSummary().compareTo(o2.getSummary());
-
- return compare;
- }
- });
-
- for (final Calendar calendar : calendars) {
- final Map> eventMap = normalize(calendar);
-
- final List events = eventMap.get(date);
-
- if (events != null) {
- sortedEvents.addAll(events);
- }
- }
-
- final Iterator iterator = sortedEvents.iterator();
- for (int i = 0; iterator.hasNext() && i < eventLimit; i++) {
- final Event event = iterator.next();
-
- final ClickableFlowPanel flowPanel = new ClickableFlowPanel();
- flowPanel.addStyleName("calendar-event");
-
- boolean fullDayEvent = false;
-
- final StringBuilder eventDate = new StringBuilder();
- eventDate.append(hourFormatter.format(event.getDtstart()));
- if (event.getDtend() != null) {
- eventDate.append(" ");
- eventDate.append(hourFormatter.format(event.getDtend()));
-
- if (event.getDtstart().getDate() != event.getDtend().getDate()
- || event.getDtstart().getMonth() != event.getDtend().getMonth()
- || event.getDtstart().getYear() != event.getDtend().getYear()) {
- fullDayEvent = true;
- flowPanel.addStyleName("calendar-fullday-event");
- }
- }
-
- final InlineLabel dateLabel = new InlineLabel(eventDate.toString());
- dateLabel.addStyleName("calendar-event-date");
-
- final InlineLabel eventLabel = new InlineLabel(event.getSummary());
- eventLabel.addStyleName("calendar-event-label");
-
- if (fullDayEvent)
- flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle());
- else
- eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle());
-
- if (!fullDayEvent)
- flowPanel.add(dateLabel);
- flowPanel.add(eventLabel);
-
- final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true);
-
- final Grid popupContent = new Grid(event.getParent().isEditable() ? 5 : 3, 1);
- popupContent.setText(0, 0, event.getSummary());
- popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header");
-
- if (!fullDayEvent) {
- popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date");
- popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle());
- popupContent.setText(1, 0, eventDate.toString());
- } else
- popupContent.setText(1, 0, "");
-
- if (event.getDescription() != null && !"".equals(event.getDescription())) {
- popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description");
- popupContent.setText(2, 0, event.getDescription());
- } else
- popupContent.setText(2, 0, "");
-
- if (event.getParent().isEditable()
- && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) {
-
- final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent());
- editAnchor.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent clickEvent) {
- delegate.edit(event, CalendarWidget.this);
- }
- });
-
- final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent());
- deleteAnchor.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent clickEvent) {
- delegate.delete(event, CalendarWidget.this);
- detailPopup.hide();
- }
- });
-
- popupContent.setWidget(3, 0, editAnchor);
- popupContent.setWidget(4, 0, deleteAnchor);
- }
-
- detailPopup.setWidget(popupContent);
-
- flowPanel.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
- final int left = flowPanel.getAbsoluteLeft() - 10;
- final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop();
-
- detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px");
-
- // Show the popup
- detailPopup.setPopupPositionAndShow(new PositionCallback() {
-
- @Override
- public void setPosition(int offsetWidth, int offsetHeight) {
- detailPopup.getElement().getStyle().setPropertyPx("left", left);
- detailPopup.getElement().getStyle().setProperty("top", "");
- detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom);
- }
- });
- }
- });
-
- cell.add(flowPanel);
- }
-
- if (eventLimit != UNDEFINED && sortedEvents.size() > eventLimit) {
- final Anchor eventLabel = new Anchor("\u25BC");
- final Date thisDate = new Date(date.getTime());
- eventLabel.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
- startDate = thisDate;
- setDisplayMode(DisplayMode.WEEK);
- }
- });
- eventLabel.addStyleName("calendar-event-limit");
- cell.add(eventLabel);
- }
- }
-
- /**
- * Returns the first date of the week that includes the given date.
- *
- * @param day
- * A date
- * @param firstDay
- * The first day of the week (such as {@link #SUNDAY}, {@link #MONDAY} or anything else).
- * @return The first date of the week that includes day, as a {@link Date}.
- */
- private static Date getFirstDateOfWeek(Date day, int firstDay) {
- final int decal = (day.getDay() + 7 - firstDay) % 7;
- return new Date(day.getYear(), day.getMonth(), day.getDate() - decal);
- }
-
- /**
- * Calculates the number of the week that includes the given date.
- *
- * @param date
- * A date
- * @param firstDay
- * The first day of the week (such as {@link #SUNDAY}, {@link #MONDAY} or anything else).
- * @return The number of the week that includes date
.
- */
- private static int getWeekNumber(Date date, int firstDay) {
- int daysToThursday = 4 - date.getDay();
-
- if (date.getDay() < firstDay)
- daysToThursday -= 7;
-
- final Date thursday = new Date(date.getYear(), date.getMonth(), date.getDate() + daysToThursday);
-
- final Date januaryFourth = new Date(thursday.getYear(), 0, 4);
- final int daysToMonday = 1 - januaryFourth.getDay(); // Essayer avec le
- // 1er jour de
- // la
- // semaine
- final Date monday = new Date(thursday.getYear(), 0, 4 + daysToMonday);
-
- final double diff = Math.floor((thursday.getTime() - monday.getTime()) / (1000 * 60 * 60 * 24));
- return (int) Math.ceil(diff / 7.0);
- }
+ /**
+ * Retrieves the current heading of the calendar.
+ *
+ * @return The heading value.
+ */
+ public String getHeading() {
+ final String title = titleFormatter.format(startDate);
+ return Character.toUpperCase(title.charAt(0)) + title.substring(1);
+ }
+
+ /**
+ * Render the calendar.
+ */
+ public void refresh() {
+ final FlexTable grid = (FlexTable) getWidget();
+ grid.removeAllRows();
+ drawEmptyCells();
+
+ if (isAttached()) {
+ calibrateCalendar();
+ drawEvents();
+ }
+ if (listener != null) {
+ listener.afterRefresh();
+ }
+ }
+
+ /**
+ * Render the whole calendar but do not render the events.
+ */
+ public void drawEmptyCells() {
+ final FlexTable grid = (FlexTable) getWidget();
+
+ final int rows = displayMode.getRows() + displayHeaders;
+ final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0);
+
+ Date date = displayMode.getStartDate(startDate, firstDayOfWeek);
+
+ // Column headers
+ if (displayHeaders != NO_HEADERS) {
+ if (displayHeaders == ALL_HEADERS) {
+ // Header of the calendar
+ final Label calendarHeader = new Label(getHeading());
+ calendarHeader.addStyleName("calendar-header");
+ grid.setWidget(0, 0, calendarHeader);
+ grid.getFlexCellFormatter().setColSpan(0, 0, columns + (displayWeekNumber ? 1 : 0));
+ }
+
+ final Date currentHeader = new Date(date.getTime());
+ for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) {
+ final Label columnHeader = new Label(headerFormatter.format(currentHeader));
+ columnHeader.addStyleName("calendar-column-header");
+ grid.setWidget(displayHeaders == ALL_HEADERS ? 1 : 0, x, columnHeader);
+
+ currentHeader.setDate(currentHeader.getDate() + 1);
+ }
+ }
+
+ int currentMonth = startDate.getMonth();
+ for (int y = displayHeaders; y < rows; y++) {
+ if (displayWeekNumber) {
+ grid.getCellFormatter().addStyleName(y, 0, "calendar-row-header");
+ grid.setText(y, 0, Integer.toString(getWeekNumber(date, firstDayOfWeek)));
+ }
+
+ for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) {
+ drawCell(y, x, date, currentMonth);
+ date.setDate(date.getDate() + 1);
+ }
+ }
+ }
+
+ /**
+ * Render the events for every cells.
+ */
+ public void drawEvents() {
+ final int rows = displayMode.getRows() + displayHeaders;
+ final int columns = displayMode.getColumns() + (displayWeekNumber ? 1 : 0);
+
+ Date date = displayMode.getStartDate(startDate, firstDayOfWeek);
+ List alreadyShownWeekViewEvents = new ArrayList();
+ int[][] theShiftVecorOfFullDayEvents = new int[8][10];
+
+ for (int y = displayHeaders; y < rows; y++) {
+ for (int x = displayWeekNumber ? 1 : 0; x < columns; x++) {
+
+ if (displayMode.equals(displayMode.MONTH)) {
+ drawFullDayEvents(y, x, date);
+ drawHourMultiDayEvents(y, x, date);
+ drawEvents(y, x, date, -1);
+ } else {
+ drawFullDayEventsForWeek(1, x, date, alreadyShownWeekViewEvents, theShiftVecorOfFullDayEvents);
+ drawHourMultiDayEventsForWeek(1, x, date, alreadyShownWeekViewEvents, theShiftVecorOfFullDayEvents);
+ drawEvents(1, x, date, getLastFDPanelInCellCounter(theShiftVecorOfFullDayEvents, x));
+ }
+ date.setDate(date.getDate() + 1);
+ }
+ if (displayMode.equals(displayMode.WEEK)) {
+ break;
+ }
+ }
+ }
+
+ private int getLastFDPanelInCellCounter(int[][] theShiftVecorOfFullDayEvents, int theDayColumn) {
+ int theFDEventInColumnMaxlength = theShiftVecorOfFullDayEvents[theDayColumn].length;
+ int theLastFDEventInCellPosition = 0;
+ for (int position = theFDEventInColumnMaxlength; position >= 0; position--) {
+ if (theShiftVecorOfFullDayEvents[theDayColumn][position] > 0) {
+ theLastFDEventInCellPosition = position;
+ break;
+ }
+ }
+ return theLastFDEventInCellPosition;
+ }
+
+ /**
+ * Render the cell located at column
, row
+ *
+ * @param row
+ * @param column
+ * @param date
+ * @param currentMonth
+ */
+ private void drawCell(int row, int column, Date date, int currentMonth) {
+ final Label header = new Label(dayFormatter.format(date));
+ header.addStyleName("calendar-cell-header");
+
+ final FlexTable grid = (FlexTable) getWidget();
+
+ grid.getCellFormatter().setStyleName(row, column, "calendar-cell");
+
+ FlowPanel cell = (FlowPanel) grid.getWidget(row, column);
+ if (cell == null) {
+ cell = new FlowPanel();
+ cell.setWidth("100%");
+
+ grid.setWidget(row, column, cell);
+ } else {
+ // Reusing an existing cell
+ cell.clear();
+ }
+
+ if (currentMonth != date.getMonth()) {
+ grid.getCellFormatter().addStyleName(row, column, "calendar-cell-other-month");
+ }
+ if (date.equals(today)) {
+ grid.getCellFormatter().addStyleName(row, column, "calendar-cell-today");
+ }
+
+ cell.add(header);
+ }
+
+ /**
+ * Display the events for the cell located at column
,
+ * row
+ *
+ * @param row
+ * @param column
+ * @param date
+ * @param currentMonth
+ */
+ private void drawEvents(int row, int column, final Date date, int startDrawPosition) {
+ final FlexTable grid = (FlexTable) getWidget();
+ int fullDayEventCounter = 0;
+ int hourMultiDayEventCounter = 0;
+
+ final FlowPanel cell = (FlowPanel) grid.getWidget(row, column);
+
+ if (cell == null) {
+ throw new NullPointerException("The specified cell (" + row + ',' + column + ") doesn't exist.");
+ }
+
+ // Displaying events
+ TreeSet sortedHourEvents = createSortedEventsSet();
+ // Displaying multi day events
+ TreeSet sortedHourMultiDayEvents = createSortedEventsSet();
+ // Displaying full day events
+ TreeSet sortedFullDayEvents = createSortedEventsSet();
+
+ for (final Calendar calendar : calendars) {
+ if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)) {
+ if (calendar.getEvents() != null) {
+ // && calendar.getEvents().size()>0) {
+ //SSS final Map> eventMap = normalize(calendar.getEvents());
+ //ss
+ Map> eventMap = normalizeHourEvents(calendar.getEvents());
+ // final Map> eventMap = normalize(eventMap2);
+ //final Map> eventMap = calendar.getEvents();
+
+ final List events = eventMap.get(date);
+ if (events != null) {
+ sortedHourEvents.addAll(events);
+ }
+ }
+ hourMultiDayEventCounter = getHourMulriDayEventCounter(calendar, date, hourMultiDayEventCounter, sortedHourMultiDayEvents);
+ fullDayEventCounter = getFullDayEventCounter(calendar, date, fullDayEventCounter, sortedFullDayEvents);
+ }
+ }
+
+ final Iterator iterator = sortedHourEvents.iterator();
+ if (startDrawPosition == -1) {
+ eventLimit = 1;
+ } else {
+ eventLimit = 99;
+ }
+
+ for (int i = 0; iterator.hasNext() && i < eventLimit; i++) {
+ final Event event = iterator.next();
+
+ final ClickableFlowPanel flowPanel = new ClickableFlowPanel();
+ flowPanel.addStyleName("calendar-event");
+
+ boolean fullDayEvent = false;
+
+ final StringBuilder eventDate = new StringBuilder();
+ eventDate.append(hourFormatter.format(event.getDtstart()));
+ if (event.getDtend() != null) {
+ eventDate.append(" ");
+ eventDate.append(hourFormatter.format(event.getDtend()));
+//SS
+// if (event.getDtstart().getDate() != event.getDtend().getDate()
+// || event.getDtstart().getMonth() != event.getDtend().getMonth()
+// || event.getDtstart().getYear() != event.getDtend().getYear()) {
+ if (event.getEventType().contains("F")) {
+ fullDayEvent = true;
+ flowPanel.addStyleName("calendar-fullday-event");
+ }
+ }
+
+ final InlineLabel dateLabel = new InlineLabel(eventDate.toString());
+ dateLabel.addStyleName("calendar-event-date");
+
+ //final InlineLabel eventLabel = new InlineLabel(event.getReferenceId()==null?event.getSummary():"--->>");
+ // final InlineLabel eventLabel = new InlineLabel(row + "; " + (!(event.getReferenceId() != null && event.getReferenceId().intValue() > 0)? event.getSummary() : event.getSummary() + "->>serial"));
+ final InlineLabel eventLabel = new InlineLabel(event.getSummary());
+ eventLabel.addStyleName("calendar-event-label");
+
+ if (fullDayEvent) {
+ flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle());
+ } else {
+ eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle());
+ }
+
+ if (!fullDayEvent) {
+ flowPanel.add(dateLabel);
+
+ int daysdiff = calculateEventDurationInDays(event);
+
+ flowPanel.setTitle(createTitleForHourEvent(daysdiff, event));
+ }
+ flowPanel.add(eventLabel);
+ if (event.getEventType().contains("H")) {
+ DOM.setStyleAttribute(flowPanel.getElement(), "background-color", "rgba(28,97,217)");
+ // DOM.setStyleAttribute(flowPanel.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)");
+ }
+ final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true);
+
+ final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1);
+ popupContent.setText(0, 0, event.getSummary());
+ popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header");
+
+ if (!fullDayEvent) {
+ popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date");
+ popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle());
+ popupContent.setText(1, 0, eventDate.toString());
+ } else {
+ popupContent.setText(1, 0, "");
+ }
+
+ if (event.getDescription() != null && !"".equals(event.getDescription())) {
+ popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description");
+ popupContent.setText(2, 0, event.getDescription());
+ } else {
+ popupContent.setText(2, 0, "");
+ }
+
+ if (event.getParent().isEditable()
+ && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) {
+
+ final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent());
+ editAnchor.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ delegate.edit(event, CalendarWidget.this);
+ }
+ });
+
+ final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent());
+ deleteAnchor.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ delegate.delete(event, CalendarWidget.this);
+ detailPopup.hide();
+ }
+ });
+
+ final Anchor deleteChainAnchor = new Anchor("Delete all recurrences");
+ deleteChainAnchor.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ delegate.deleteChain(event, CalendarWidget.this);
+ refresh();
+ detailPopup.hide();
+
+ }
+ });
+
+ popupContent.setWidget(3, 0, editAnchor);
+ popupContent.setWidget(4, 0, deleteAnchor);
+ if (!event.getEventType().contains("O")) {
+ popupContent.setWidget(5, 0, deleteChainAnchor);
+ }
+ }
+
+ detailPopup.setWidget(popupContent);
+
+ flowPanel.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ final int left = flowPanel.getAbsoluteLeft() - 10;
+ final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop();
+
+ detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px");
+
+ // Show the popup
+ detailPopup.setPopupPositionAndShow(new PositionCallback() {
+
+ @Override
+ public void setPosition(int offsetWidth, int offsetHeight) {
+ detailPopup.getElement().getStyle().setPropertyPx("left", left);
+ detailPopup.getElement().getStyle().setProperty("top", "");
+ detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom);
+ }
+ });
+ }
+ });
+
+ if (startDrawPosition != -1) {
+ int height = 12;
+ int top = startDrawPosition > 0 ? (startDrawPosition - 1) * height : 0;
+ DOM.setStyleAttribute(flowPanel.getElement(), "position", "relative");
+ DOM.setStyleAttribute(flowPanel.getElement(), "top", top + "px");
+ // startDrawPosition ++;
+ }
+ cell.add(flowPanel);
+ }
+
+ // if (eventLimit != UNDEFINED && (fullDayEventCounter + sortedHourEvents.size()) > eventLimit) {
+ if (startDrawPosition == -1 && eventLimit != UNDEFINED && (hourMultiDayEventCounter + fullDayEventCounter + sortedHourEvents.size()) > 1) {
+ //final Anchor eventLabel = new Anchor("\u25BC +" + (sortedHourEvents.size()-eventLimit) + " st:" + fullDayEventCounter +" fd events");
+ final Anchor eventLabel = new Anchor("\u25BC " + (sortedHourEvents.size() + hourMultiDayEventCounter + fullDayEventCounter) + " events");
+ // eventLabel.setTitle("Click to view all events of the day.");
+ final Date thisDate = new Date(date.getTime());
+ String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate);
+ eventLabel.setTitle(theDateString + "\nClick to view all events of the day:"
+ + "\nOne day events: " + sortedHourEvents.size()
+ + "\nMulti day events: " + hourMultiDayEventCounter
+ + "\nFull day events: " + fullDayEventCounter);
+
+ eventLabel.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ startDate = thisDate;
+ setDisplayMode(DisplayMode.WEEK);
+ }
+ });
+ eventLabel.addStyleName("calendar-event-limit");
+ DOM.setStyleAttribute(eventLabel.getElement(), "border-color", "#1c61d9");
+ DOM.setStyleAttribute(eventLabel.getElement(), "border-style", "solid");
+ DOM.setStyleAttribute(eventLabel.getElement(), "border-width", "1px");
+
+// if (fullDayEventCounter > 0
+//
+//
+// sortedHourEvents.size() //-- DOM.setStyleAttribute(eventLabel.getElement(), "position", "relative");
+ // DOM.setStyleAttribute(eventLabel.getElement(), "top", (cell.getOffsetHeight()-16) + "px");
+ //-- DOM.setStyleAttribute(eventLabel.getElement(), "top", (cell.getAbsoluteTop() + 30) + "px");
+ // Window.alert(cell.getTitle() + " cell.getOffsetHeight()="+cell.getOffsetHeight()
+ // + " - " + " cell.getAbsoluteTop())=" + cell.getAbsoluteTop()
+ // + " Label OffsetHeight = " + eventLabel.getElement().getOffsetHeight()+
+ // " cell.getElement() OffsetHeight =" + cell.getElement().getOffsetHeight()+
+ // " cell.getElement() AbsoluteBottom=" + cell.getElement().getAbsoluteBottom()+
+ // " cell.getElement() ClientHeight =" + cell.getElement().getClientHeight()
+ // ) ;
+/* int chiled = grid.getCellFormatter().getElement(row, column).getChildCount();
+
+ int gridHeight = grid.getOffsetHeight();
+ int weekdayRowHeight = grid.getRowFormatter()
+ .getElement(0).getOffsetHeight();
+ */
+// Window.alert("chiled=" + chiled + " gridHeight =" + gridHeight
+// + " weekdayRowHeight =" + weekdayRowHeight
+// );
+ cell.add(eventLabel);
+ }
+ }
+
+ private int getHourMulriDayEventCounter(final Calendar calendar, final Date date, int hourMultiDayEventCounter, TreeSet sortedHourMultiDayEvents) {
+ //hourMultiDayEventCounter
+ if (calendar.getHourMultiDayEvents() != null) {
+ final Map> hourMultiDayEventMap = normalize(calendar.getHourMultiDayEvents());
+ for (Map.Entry> entry : hourMultiDayEventMap.entrySet()) {
+ Date key = entry.getKey();
+ List value = entry.getValue();
+ for (Iterator iterator = value.iterator(); iterator.hasNext();) {
+ Event next = iterator.next();
+// Date theStartEventDate = next.getDtstart();
+// Date theEndEventDate = next.getDtend();
+
+ Date theStartEventDateWithTime = next.getDtstart();
+ Date theEndEventDateWithTime = next.getDtend();
+
+ Date theStartEventDate = new Date(date.getTime());
+ Date theEndEventDate = new Date(date.getTime());
+
+ theStartEventDate.setYear(theStartEventDateWithTime.getYear());
+ theStartEventDate.setMonth(theStartEventDateWithTime.getMonth());
+ theStartEventDate.setDate(theStartEventDateWithTime.getDate());
+
+ theEndEventDate.setYear(theEndEventDateWithTime.getYear());
+ theEndEventDate.setMonth(theEndEventDateWithTime.getMonth());
+ theEndEventDate.setDate(theEndEventDateWithTime.getDate());
+//<----
+
+ if (next.getEventType().contains("H")
+ && date.after(theStartEventDate) && date.before(theEndEventDate)
+ || date.equals(theStartEventDate)
+ || date.equals(theEndEventDate)) {
+ hourMultiDayEventCounter++;
+ }
+ }
+ }
+ final List fullDayEvents = hourMultiDayEventMap.get(date);
+ if (fullDayEvents != null) {
+ sortedHourMultiDayEvents.addAll(fullDayEvents);
+ }
+ }
+ return hourMultiDayEventCounter;
+ }
+
+ private int getFullDayEventCounter(final Calendar calendar, final Date date, int fullDayEventCounter, TreeSet sortedFullDayEvents) {
+ if (calendar.getFullDayEvents() != null) {
+ final Map> fullDayEventMap = normalize(calendar.getFullDayEvents());
+ for (Map.Entry> entry : fullDayEventMap.entrySet()) {
+ Date key = entry.getKey();
+ List value = entry.getValue();
+ for (Iterator iterator = value.iterator(); iterator.hasNext();) {
+ Event next = iterator.next();
+ Date theStartEventDate = next.getDtstart();
+ Date theEndEventDate = next.getDtend();
+ if (next.getEventType().contains("F")
+ && date.after(theStartEventDate) && date.before(theEndEventDate)
+ || date.equals(theStartEventDate)
+ || date.equals(theEndEventDate)) {
+ fullDayEventCounter++;
+ }
+ }
+
+ }
+ final List fullDayEvents = fullDayEventMap.get(date);
+ if (fullDayEvents != null) {
+ sortedFullDayEvents.addAll(fullDayEvents);
+ }
+ }
+ return fullDayEventCounter;
+ }
+
+ private static int calculateEventDurationInDays(final Event event) {
+ long diff = event.getDtend().getTime() - event.getDtstart().getTime();
+ long diffDays = diff / (24 * 60 * 60 * 1000) + 1;
+ int daysdiff = (int) diffDays;
+ return daysdiff;
+ }
+
+ /**
+ * Returns the first date of the week that includes the given date.
+ *
+ * @param day A date
+ * @param firstDay The first day of the week (such as
+ * {@link #SUNDAY}, {@link #MONDAY} or anything else).
+ * @return The first date of the week that includes day, as a
+ * {@link Date}.
+ */
+ private static Date getFirstDateOfWeek(Date day, int firstDay) {
+ final int decal = (day.getDay() + DAYS_IN_A_WEEK - firstDay) % DAYS_IN_A_WEEK;
+ return new Date(day.getYear(), day.getMonth(), day.getDate() - decal);
+ }
+
+ /**
+ * Calculates the number of the week that includes the given date.
+ *
+ * @param date A date
+ * @param firstDay The first day of the week (such as
+ * {@link #SUNDAY}, {@link #MONDAY} or anything else).
+ * @return The number of the week that includes date
.
+ */
+ private static int getWeekNumber(Date date, int firstDay) {
+ int daysToThursday = 4 - date.getDay();
+
+ if (date.getDay() < firstDay) {
+ daysToThursday -= DAYS_IN_A_WEEK;
+ }
+
+ final Date thursday = new Date(date.getYear(), date.getMonth(), date.getDate() + daysToThursday);
+
+ final Date januaryFourth = new Date(thursday.getYear(), 0, 4);
+ final int daysToMonday = 1 - januaryFourth.getDay(); // Essayer avec le
+ // 1er jour de
+ // la
+ // semaine
+ final Date monday = new Date(thursday.getYear(), 0, 4 + daysToMonday);
+
+ final double diff = Math.floor((thursday.getTime() - monday.getTime()) / (1000 * 60 * 60 * 24));
+ return (int) Math.ceil(diff / 7.0);
+ }
+
+ private void placeItemInGridMonth(Widget panel, int colStart, int colEnd,
+ int row, int cellPosition) {
+ final FlexTable grid = (FlexTable) getWidget();
+ // FlowPanel cell = (FlowPanel) grid.getWidget(1, 1);
+ FlowPanel cell = (FlowPanel) grid.getWidget(row, colStart);
+ cell.add(panel);
+ calculatedCellOffsetHeight = cell.getElement().getClientHeight();//OffsetHeight();
+
+ int height = appointmentHeight();
+ height = 12;
+ //float width = ((float) (colEnd - colStart) / (float) DAYS_IN_A_WEEK) * 100f - 1f;
+ float width = (colEnd - colStart) * 100f;
+
+ float top = 0;
+
+ cell = (FlowPanel) grid.getWidget(row, colStart);
+
+ setFullDayEventStyle(panel, top, width, height);
+ }
+
+ private static int appointmentPaddingTop() {
+ return 1 + (Math.abs(FormattingUtil.getBorderOffset()) * 3);
+ }
+
+ private static int appointmentHeight() {
+ // TODO: calculate appointment height dynamically
+ return 12;
+ }
+
+ /**
+ * Display full day events with started date
+ *
+ * @param row
+ * @param column
+ * @param date
+ */
+ private void drawFullDayEvents(int row, int column, final Date date) {
+
+ TreeSet sortedFullDayEvents = createSortedEventsSet();
+
+ for (final Calendar calendar : calendars) {
+ if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)
+ && calendar.getFullDayEvents() != null) {
+ final Map> fullDayEventMap = normalize(calendar.getFullDayEvents());
+ final List fullDayEvents = fullDayEventMap.get(date);
+ if (fullDayEvents != null) {
+ sortedFullDayEvents.addAll(fullDayEvents);
+ }
+ }
+ }
+
+ final Iterator iterator = sortedFullDayEvents.iterator();
+
+ eventLimit = 1;//999
+ for (int i = 0; iterator.hasNext() && i < eventLimit; i++) {
+ final Event event = iterator.next();
+ final ClickableFlowPanel flowPanelFullDayFirst = createFullDayPanel(event);
+ final ClickableFlowPanel flowPanelFullDayContinue = createFullDayPanel(event);
+ final FlexTable grid = (FlexTable) getWidget();
+ int daysdiff = calculateEventDurationInDays(event);
+
+ //String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate);
+ flowPanelFullDayFirst.setTitle(createTitleForFullDayEvent(daysdiff, event));
+
+ if (column + daysdiff - 1 < 8) {
+ placeItemInGridMonth(flowPanelFullDayFirst, column, column + daysdiff, row, i);
+ } else {
+ placeItemInGridMonth(flowPanelFullDayFirst, column, 8, row, i);
+ if (row <= 5) {
+ flowPanelFullDayContinue.setTitle(createTitleForFullDayEvent(daysdiff, event));
+ placeItemInGridMonth(flowPanelFullDayContinue, 1, 1 + daysdiff - (8 - column), row + 1, i);
+ }
+ }
+ }
+ }
+
+ /**
+ * Display full day events with started date
+ *
+ * @param row
+ * @param column
+ * @param date
+ */
+ private void drawHourMultiDayEvents(int row, int column, final Date date) {
+
+ TreeSet sortedFullDayEvents = createSortedEventsSet();
+
+ for (final Calendar calendar : calendars) {
+ if (!(calendar.getIdentifier() instanceof ActivityCalendarIdentifier)
+ && calendar.getFullDayEvents() != null) {
+ final Map> fullDayEventMap = normalize(calendar.getHourMultiDayEvents());//EE
+ final List fullDayEvents = fullDayEventMap.get(date);
+ if (fullDayEvents != null) {
+ sortedFullDayEvents.addAll(fullDayEvents);
+ }
+ }
+ }
+
+ final Iterator iterator = sortedFullDayEvents.iterator();
+
+ eventLimit = 1;//999
+ for (int i = 0; iterator.hasNext() && i < eventLimit; i++) {
+ final Event event = iterator.next();
+ final ClickableFlowPanel flowPanelFullDayFirst = createFullDayPanel(event);
+ final ClickableFlowPanel flowPanelFullDayContinue = createFullDayPanel(event);
+ final FlexTable grid = (FlexTable) getWidget();
+ int daysdiff = calculateEventDurationInDays(event);
+
+ //String theDateString = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(thisDate);
+ flowPanelFullDayFirst.setTitle(createTitleForHourMultiDayEvent(daysdiff, event));//EE3
+ DOM.setStyleAttribute(flowPanelFullDayFirst.getElement(), "background-color", "rgba(28,97,217)");
+ DOM.setStyleAttribute(flowPanelFullDayFirst.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)");
+ if (column + daysdiff - 1 < 8) {
+ placeItemInGridMonth(flowPanelFullDayFirst, column, column + daysdiff, row, i);
+ } else {
+ placeItemInGridMonth(flowPanelFullDayFirst, column, 8, row, i);
+ if (row <= 5) {
+ flowPanelFullDayContinue.setTitle(createTitleForHourMultiDayEvent(daysdiff, event));//EE2
+ DOM.setStyleAttribute(flowPanelFullDayContinue.getElement(), "background-color", "rgba(28,97,217)");
+ DOM.setStyleAttribute(flowPanelFullDayContinue.getElement(), "background", "linear-gradient(-90deg, #1c61d9, #0000)");
+ placeItemInGridMonth(flowPanelFullDayContinue, 1, 1 + daysdiff - (8 - column), row + 1, i);
+ }
+ }
+ }
+ }
+
+ private static String createTitleForFullDayEvent(int daysdiff, final Event event) {
+ return "Event: " + event.getSummary()
+ + "\nDescr: " + (event.getDescription() != null ? event.getDescription() : "")
+ + "\nDuration: " + daysdiff + " full day" + (daysdiff > 1 ? "s." : ".")
+ + (event.getDtstart().equals(event.getDtend())
+ ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()))
+ : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())
+ + " To " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend())));
+ }
+
+ private static String createTitleForHourMultiDayEvent(int daysdiff, final Event event) {
+ return "Event: " + event.getSummary()
+ + "\nDescr: " + (event.getDescription() != null ? event.getDescription() : "")
+ + "\nDuration: " + daysdiff + " day" + (daysdiff > 1 ? "s." : ".")
+ + (event.getDtstart().equals(event.getDtend())
+ ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()))
+ : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())
+ + " " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.HOUR24_MINUTE).format(event.getDtstart())
+ + " \nTo " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend())
+ + " " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.HOUR24_MINUTE).format(event.getDtend())));
+ }
+
+ /**
+ *
+ * @param daysdiff the value of daysdiff
+ * @param event the value of event
+ * @return the java.lang.String
+ */
+ private String createTitleForHourEvent(int daysdiff, final Event event) {
+ String duration = hourFormatter.format(new Date(event.getDtend().getTime() - event.getDtstart().getTime()));
+ long millis = event.getDtend().getTime() - event.getDtstart().getTime();
+ long minute = (millis / (1000 * 60)) % 60;
+ long hour = (millis / (1000 * 60 * 60)) % 24;
+ return "Hour Event: " + event.getSummary()
+ + "\nDescr: " + (event.getDescription() != null ? event.getDescription() : "")
+ + "\nDuration: from " + hourFormatter.format(event.getDtstart())
+ + " to " + hourFormatter.format(event.getDtend())
+ // + " (" + duration + " hours" + (daysdiff > 0 ? " every day)" : ")")
+ + " (" + (hour > 0 ? (hour + " hours ") : "")
+ + (minute > 0 ? (minute + " minutes") : "") + (daysdiff > 1 ? " every day)" : ") ")
+ + (daysdiff > 1 ? (daysdiff + " days in row. ") : " ")
+ + (isSameDay(event.getDtstart(), event.getDtend())
+ ? (DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart()))
+ : ("\nFrom " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtstart())
+ + " to " + DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.YEAR_MONTH_WEEKDAY_DAY).format(event.getDtend())));
+ }
+
+ /**
+ * @param event
+ * @return
+ */
+ private ClickableFlowPanel createFullDayPanel(final Event event) {
+ final ClickableFlowPanel flowPanel = new ClickableFlowPanel();
+ flowPanel.addStyleName("calendar-event");
+
+ boolean fullDayEvent = false;
+
+ final StringBuilder eventDate = new StringBuilder();
+ eventDate.append(hourFormatter.format(event.getDtstart()));
+ if (event.getDtend() != null) {
+ eventDate.append(" ");
+ eventDate.append(hourFormatter.format(event.getDtend()));
+ fullDayEvent = true;
+ flowPanel.addStyleName("calendar-fullday-event");
+ }
+
+ final InlineLabel dateLabel = new InlineLabel(eventDate.toString());
+ dateLabel.addStyleName("calendar-event-date");
+
+ final InlineLabel eventLabel = new InlineLabel(event.getEventType().contains("H") ? (hourFormatter.format(event.getDtstart()) + " " + event.getSummary()) : event.getSummary());
+ //final InlineLabel eventLabel = new InlineLabel(event.getDtstart().getDate() + "; " + (event.getReferenceId()==null?event.getSummary():event.getSummary()) + "+>>");
+ eventLabel.addStyleName("calendar-event-label");
+
+ if (fullDayEvent) {
+ flowPanel.addStyleName("calendar-fullday-event-" + event.getParent().getStyle());
+ } else {
+ eventLabel.addStyleName("calendar-event-" + event.getParent().getStyle());
+ }
+
+ if (!fullDayEvent) {
+ flowPanel.add(dateLabel);
+ }
+ flowPanel.add(eventLabel);//ak
+ //flowPanel.setTitle(event.getSummary());
+
+ final DecoratedPopupPanel detailPopup = new DecoratedPopupPanel(true);
+
+ final Grid popupContent = new Grid(event.getParent().isEditable() ? 6 : 3, 1);
+ popupContent.setText(0, 0, event.getSummary());
+ popupContent.getCellFormatter().addStyleName(0, 0, "calendar-popup-header");
+
+ if (!fullDayEvent) {
+ popupContent.getCellFormatter().addStyleName(1, 0, "calendar-popup-date");
+ popupContent.getCellFormatter().addStyleName(1, 0, "calendar-event-" + event.getParent().getStyle());
+ popupContent.setText(1, 0, eventDate.toString());
+ } else {
+ popupContent.setText(1, 0, "");
+ }
+
+ if (event.getDescription() != null && !"".equals(event.getDescription())) {
+ popupContent.getCellFormatter().addStyleName(2, 0, "calendar-popup-description");
+ popupContent.setText(2, 0, event.getDescription());
+ } else {
+ popupContent.setText(2, 0, "");
+ }
+
+ if (event.getParent().isEditable()
+ && ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT_AGENDA)) {
+
+ final Anchor editAnchor = new Anchor(I18N.CONSTANTS.calendarEditEvent());
+ editAnchor.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ delegate.edit(event, CalendarWidget.this);
+ }
+ });
+
+ final Anchor deleteAnchor = new Anchor(I18N.CONSTANTS.calendarDeleteEvent());
+ deleteAnchor.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ delegate.delete(event, CalendarWidget.this);
+ refresh();
+ detailPopup.hide();
+ }
+ });
+
+ final Anchor deleteChainAnchor = new Anchor("Delete all recurrences");
+ deleteChainAnchor.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent clickEvent) {
+ delegate.deleteChain(event, CalendarWidget.this);
+ refresh();
+ detailPopup.hide();
+
+ }
+ });
+
+ popupContent.setWidget(3, 0, editAnchor);
+ popupContent.setWidget(4, 0, deleteAnchor);
+ if (!event.getEventType().contains("O")) {
+ popupContent.setWidget(5, 0, deleteChainAnchor);
+ }
+ }
+
+ detailPopup.setWidget(popupContent);
+
+ flowPanel.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ final int left = flowPanel.getAbsoluteLeft() - 10;
+ final int bottom = Window.getClientHeight() - flowPanel.getAbsoluteTop();
+
+ detailPopup.setWidth((getCellWidth(CELL_DEFAULT_WIDTH) + 20) + "px");
+
+ // Show the popup
+ detailPopup.setPopupPositionAndShow(new PositionCallback() {
+
+ @Override
+ public void setPosition(int offsetWidth, int offsetHeight) {
+ detailPopup.getElement().getStyle().setPropertyPx("left", left);
+ detailPopup.getElement().getStyle().setProperty("top", "");
+ detailPopup.getElement().getStyle().setPropertyPx("bottom", bottom);
+ }
+ });
+ }
+ });
+ return flowPanel;
+ }
+
+ /**
+ * Calculates the height of each day cell in the Month grid. It excludes the
+ * height of each day's header, as well as the overall header that shows the
+ * weekday labels.
+ */
+// private void calculateCellHeight() {
+//
+// int gridHeight = monthCalendarGrid.getOffsetHeight();
+// int weekdayRowHeight = monthCalendarGrid.getRowFormatter()
+// .getElement(0).getOffsetHeight();
+// int dayHeaderHeight = dayLabels.get(0).getOffsetHeight();
+//
+// calculatedCellOffsetHeight = (float) (gridHeight - weekdayRowHeight)
+// / monthViewRequiredRows;
+// calculatedCellHeight = calculatedCellOffsetHeight - dayHeaderHeight;
+// calculatedWeekDayHeaderHeight = weekdayRowHeight;
+// calculatedDayHeaderHeight = dayHeaderHeight;
+// }
+ private TreeSet