The MindFusion Forums
Scheduling and Gantt Components >> Java Swing >> Recurrence
https://mindfusion.eu/Forum/YaBB.pl?num=1499089982

Message started by Ionut Murarasu on Jul 3rd, 2017 at 1:53pm

Title: Recurrence
Post by Ionut Murarasu on Jul 3rd, 2017 at 1:53pm
Hello,

I need some help with a problem.
I want to add some recurrence appointments in my calendar.
After I added an appointment with recurrence in the calendar, in the appointment an icon with two circular arrows appears, that means my appointment was added as recurrence.
But after I made a change in the appointment, like name or change the capacity of the interval those two arrows are underline and my modifications are made only for the appointment from my current day not the entire recurrence period.

For example my appointment has recurrence for every Monday, but if I try to change the name, it's change only for the current day, not for every Monday.

I need some help with this problem, please.

This is the way how I added a recurrence when I created the appointment:

Recurrence recurrencae = new Recurrence();
recurrence.setPattern(RecurrencePattern.Daily);
recurrence.setOccurrence(Occurrence.First);
recurrence.setDays(7);
recurrence.setStartDate(date);
recurrence.setRecurrenceEnd(RecurrenceEnd.Never);
app.setRecurrence(recurrence);


recurrence.JPG ( 69 KB | 179 Downloads )

Title: Re: Recurrence
Post by Meppy on Jul 3rd, 2017 at 2:13pm
Hi,

Modifying a recurring appointment modifies the instance only (not the master) and causes an exception to be automatically created. If you want to apply the modification to the master (and to all the occurrences), handle the itemModifed event:

[code]calendar.addCalendarListener(new CalendarAdapter() {
     @Override
     public void itemModified(ItemModifiedEvent e) {
           // TODO Auto-generated method stub
           super.itemModified(e);

           if (e.getItem().getRecurrenceState() == RecurrenceState.Exception)
           {
                 Item master = e.getItem().getRecurrence().getMaster();
                 master.setStartTime(e.getItem().getStartTime());
                 master.setEndTime(e.getItem().getEndTime());
                 e.getItem().getRecurrence().removeException(e.getItem());
           }
     }
}[/code]
Regards,
Meppy

Title: Re: Recurrence
Post by Ionut Murarasu on Jul 3rd, 2017 at 2:26pm
Thanks !

I will try.

Title: Re: Recurrence
Post by Ionut Murarasu on Jul 4th, 2017 at 7:28am
Hello again,

First time I want to thank you for your help!
It works when I try to change the change the interval and remains recurring, but I can't move the appointment to another day.
I can't  drag the item from today to tomorrow.
Why is this happening ?

Title: Re: Recurrence
Post by Meppy on Jul 4th, 2017 at 11:11am
Hi,

If you want to adjust the start of the recurrence, you can do this through the Recurrence.setStartDate method. In your case you can detect if the user moved an item to another day and adjust the recurrence pattern appropriately:

[code]int fromDay = (int)((e.getOldStartTime().getTicks() - e.getOldStartTime().getTimeOfDay().getTicks()) / Duration.TicksPerDay);
int toDay = (int)((e.getItem().getStartTime().getTicks() - e.getItem().getStartTime().getTimeOfDay().getTicks()) / Duration.TicksPerDay);
if (fromDay != toDay)
     e.getItem().getRecurrence().setStartDate(e.getItem().getRecurrence().getStartDate().addDays(toDay - fromDay));[/code]
I hope this help.

Regards,
Meppy

Title: Re: Recurrence
Post by Ionut Murarasu on Jul 4th, 2017 at 1:10pm
Thanks for your answer.

I have one more little problem. When I try to remove a recurring appointment, all items are removed without the first one from where series started.

See print screen in the attachment.

In the first image I tried to remove the second appointment but almost all was removed without the first one. Also in the first item the recurring icon was removed and become non recurring.

Can you help me please with a solution to remove the entire series ?

I added this code to remove the recurring

@Override
public void itemDeleted(ItemEvent e) {
     super.itemDeleted(e);
     
     if (e.getItem().getRecurrenceState() == RecurrenceState.Exception) {
           Item master = e.getItem().getRecurrence().getMaster();
           master.setRecurrence(null);
     }
}

rec1.JPG ( 40 KB | 176 Downloads )

Title: Re: Recurrence
Post by Meppy on Jul 5th, 2017 at 6:04am
Hi,

You need to also remove the master item from the schedule:

[code]calendar.getSchedule().getItems().remove(master);[/code]
Regards,
Meppy

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.