Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Recurrence (Read 2426 times)
annievalki
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: May 26th, 2020
Recurrence
May 30th, 2020 at 12:08am
Print Post  
I have a Timetable view Calendar.
I have a CalendarListeners:
I create a new appointment item, and a recurrence on x day of the week.

Its all work.. but later I change the duration of the item by a drag, and I would like that it changed to in the recurrence.
I tried it with CalendarListener.draw but it creates a infinite bucle.

any idea?

public void itemCreated(ItemEvent e) {
muestra(e);
}
public void draw(CalendarDrawEvent e) {
                       
}

private void muestra(ItemEvent e) {
//aqui puedo guardar los datos del evento

calendar1.beginInit();
int dayIndex = e.getItem().getStartTime().getDayOfWeek().getValue();


Appointment app = new Appointment();
app.setHeaderText(e.getItem().getHeaderText());

app.setStartTime(e.getItem().getStartTime());
app.setEndTime(e.getItem().getEndTime());
calendar1.getSchedule().getItems().add(app);
calendar1.setTheme(ThemeType.Light);
String fechaIni = e.getItem().getStartTime().toString();
String fechaFin = e.getItem().getEndTime().toString();

Recurrence rec = new Recurrence();
rec.setPattern(RecurrencePattern.Weekly);
rec.setDaysOfWeek(EnumSet.of(dia(dayIndex)));
rec.setStartDate(e.getItem().getStartTime().addDays(6));
rec.setRecurrenceEnd(RecurrenceEnd.Never);
app.setRecurrence(rec);
e.getItem().setRecurrence(rec);


calendar1.endInit();}
« Last Edit: May 30th, 2020 at 6:34am by annievalki »  
Back to top
 
IP Logged
 
Iva_P
YaBB Moderator
*****
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: Recurrence
Reply #1 - May 30th, 2020 at 1:20pm
Print Post  
Hello,

Handle the itemModified event, which will be raised when the user has modified any of the recurrent events:

Code (Java)
Select All
calendar.addCalendarListener(new CalendarAdapter(){
			public void itemModified (ItemModifiedEvent  e) {
				onItemModified(e);
			}
		});
 



In the event handler get the Master item, that is the prototype of the Recurrence and all recurrent events are created after it. Then copy the changes on the event to the Master item. Finally, reset the state for all items of this recurrence because when an instance is edited it is tuned into an "Exception". We want that it remains a regular occurrence.

Code (Java)
Select All
protected void onItemModified(ItemModifiedEvent e)
{
	Item master = null;

	if( e.getItem().getRecurrenceState() != RecurrenceState.Master)
		master = e.getItem().getRecurrence().getMaster();

	if(master != null)
	{
		DateTime newStart = e.getItem().getStartTime();
		DateTime newEnd = e.getItem().getEndTime();

		DateTime start = master.getStartTime();
		DateTime end = master.getEndTime();

		master.setStartTime(new DateTime(start.getYear(), start.getMonth(), start.getDay(),
							newStart.getHour(), newStart.getMinute(), newStart.getSecond()));

    	     master.setEndTime(new DateTime(end.getYear(), end.getMonth(), end.getDay(),
					newEnd.getHour(), newEnd.getMinute(), newEnd.getSecond()));

	master.getRecurrence().clearExceptions();


   }
}
 

  
Back to top
 
IP Logged
 
annievalki
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: May 26th, 2020
Re: Recurrence
Reply #2 - May 30th, 2020 at 3:57pm
Print Post  
Mm I tryied it and when I move the initical item its return an Exception:


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
     at Horario.Horario2.onItemModified(Horario2.java:168)
     at Horario.Horario2$1.itemModified(Horario2.java:91)
     at com.mindfusion.scheduling.Calendar.onItemModified(Unknown Source)
     at com.mindfusion.scheduling.Calendar.a(Unknown Source)
     at com.mindfusion.scheduling.aS.complete(Unknown Source)
     at com.mindfusion.scheduling.Calendar.c(Unknown Source)
     at com.mindfusion.scheduling.Calendar.mouseReleased(Unknown Source)
     at java.desktop/java.awt.Component.processMouseEvent(Component.java:6636)
     at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
     at java.desktop/java.awt.Component.processEvent(Component.java:6401)
     at java.desktop/java.awt.Container.processEvent(Container.java:2263)
     at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5012)
     at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
     at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
     at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:49
18)
     at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:454
7)
     at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
     at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
     at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2762)
     at java.desktop/java.awt.Component.dispatchEvent(Component.java:4844)
     at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
     at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
     at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
     at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)

     at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPr
ivilege(ProtectionDomain.java:85)
     at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPr
ivilege(ProtectionDomain.java:95)
     at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
     at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
     at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)

     at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPr
ivilege(ProtectionDomain.java:85)
     at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
     at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchTh
read.java:203)
     at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThrea
d.java:124)
     at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchTh
read.java:113)
     at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:10
9)
     at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:10
1)
     at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)








Here is my code, if it could be of help to resolve the problem :
public class Horario2 extends javax.swing.JFrame {

    Calendar c = Calendar.getInstance();

    /**
     * Creates new form Horario2
     */
    public Horario2() {
        initComponents();

        //---------------------------calendario
        calendar1.setInteractiveItemType(MyEvent.class);
        calendar1.setCustomDraw(EnumSet.of(CustomDrawElements.TimetableItem));
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(screenSize);//estas dos funciones sirven para poner pantalla completa el jFrame
        calendar1.setTheme(ThemeType.Light);//elegimos colorines
        Container cp = getContentPane();//capa de panel
        cp.setLayout(new BorderLayout());//panel con una layout preestablecida
        cp.add(jPanel1, BorderLayout.PAGE_START);//coloco objetos donde me de la santisima gana
        cp.add(calendar1, BorderLayout.CENTER);
        calendar1.setCurrentView(CalendarView.Timetable);
        calendar1.getTimetableSettings().setTwelveHourFormat(false);
        calendar1.getTimetableSettings().setHeaderDateFormat("EEEE");
        calendar1.getTimetableSettings().setStartTime(420);
        com.mindfusion.common.Duration duration1 = new com.mindfusion.common.Duration(1, 0, 0);
        calendar1.getTimetableSettings().setCellTime(duration1);
        calendar1.getTimetableSettings().setCellSize(50);

        //______----------------------fechas
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);//dia de hoy + lunes me da la fecha del lunes
        int dia = c.get(Calendar.DAY_OF_MONTH);
        int mes = c.get(Calendar.MONTH) + 1;
        int anio = c.get(Calendar.YEAR);

        DateTime date = new DateTime(anio, mes, dia);//inicializo la nueva fecha

        calendar1.getTimetableSettings().getDates().clear();
        for (int i = 0; i < 14; i++) {
            calendar1.getTimetableSettings().getDates().add(date.addDays(i));
        }
        calendar1.getTimetableSettings().setVisibleColumns(14);//uso las fecha que me muetre a partir del dia Lunes 7 dias

        //-----------------------------Listener
        calendar1.addCalendarListener(new CalendarAdapter() {

            public void itemCreated(ItemEvent e) {

                onDateClicked(e);
            }
            
          
                 public void itemModified (ItemModifiedEvent  e) {
                       onItemModified(e);
                 }
           
            
            
                

        });

    }

    private void onDateClicked(ItemEvent e) {
        calendar1.beginInit();
        int dayIndex = e.getItem().getStartTime().getDayOfWeek().getValue();

        Appointment item = new Appointment();
        item.setStartTime(e.getItem().getStartTime());
        item.setEndTime(e.getItem().getEndTime());
        item.setHeaderText(e.getItem().getHeaderText());

        item.getStyle().setBrush(Brushes.LightSkyBlue);

        // Create the recurrence pattern.
        Recurrence recurrence = new Recurrence();
        recurrence.setPattern(RecurrencePattern.Weekly);
        recurrence.setDaysOfWeek(EnumSet.of(dia(dayIndex)));
        recurrence.setStartDate(e.getItem().getStartTime().addDays(6));
        recurrence.setEndDate(e.getItem().getEndTime().addDays(6));
        recurrence.setRecurrenceEnd(RecurrenceEnd.Never);
        item.setRecurrence(recurrence);

        calendar1.getSchedule().getItems().add(item);
        calendar1.endInit();
       
      
     

    }
protected void onItemModified(ItemModifiedEvent e)
{
     Item master = null;

     if( e.getItem().getRecurrenceState() != RecurrenceState.Master)
        {master = e.getItem().getRecurrence().getMaster();}

     if(master != null)
     {
           DateTime newStart = e.getItem().getStartTime();
           DateTime newEnd = e.getItem().getEndTime();

           DateTime start = master.getStartTime();
           DateTime end = master.getEndTime();

           master.setStartTime(new DateTime(start.getYear(), start.getMonth(), start.getDay(),
                                         newStart.getHour(), newStart.getMinute(), newStart.getSecond()));

              master.setEndTime(new DateTime(end.getYear(), end.getMonth(), end.getDay(),
                             newEnd.getHour(), newEnd.getMinute(), newEnd.getSecond()));

     master.getRecurrence().clearExceptions();


   }
}


    public DayOfWeek dia(int i) {
        DayOfWeek a = DayOfWeek.Monday;
        switch (i) {
            case 1:
                a = DayOfWeek.Monday;
                break;
            case 2:
                a = DayOfWeek.Tuesday;
                break;
            case 3:
                a = DayOfWeek.Wednesday;
                break;
            case 4:
                a = DayOfWeek.Thursday;
                break;
            case 5:
                a = DayOfWeek.Friday;
                break;
            case 6:
                a = DayOfWeek.Saturday;
                break;
            default:
                a = DayOfWeek.Sunday;
                break;

        }

        return a;
    }
  

excepcion.png ( 32 KB | 140 Downloads )
excepcion.png
Back to top
 
IP Logged
 
Iva_P
YaBB Moderator
*****
Offline


I Love MindFusion!

Posts: 41
Joined: Jun 19th, 2013
Re: Recurrence
Reply #3 - May 30th, 2020 at 4:44pm
Print Post  
There are several things to be corrected in the code you've posted.
First, the line:

Code (Java)
Select All
calendar1.setInteractiveItemType(MyEvent.class); 



shows that once the user types in, an event of class MyEvent will be created. Please read the topic "Recurrence" in the online documentation https://www.mindfusion.eu/onlinehelp/jplanner/index.htm?Recurrence_0.htm, where in the "Note" section it is explained that Recurrence is not automatically supported in custom item classes. There is link to Tutorial 3 https://www.mindfusion.eu/onlinehelp/jplanner/index.htm?Tutorial_3__Creating_Cus... which shows how to create a custom Appointment that supports recurrence.

So, in the itemCreated event handler the created item is of type MyEvent and you create a new item of type Appointment to which you copy the data from the MyEvent item. That means you have two identical items - one is MyEvent and the other Appointment with recurrence. You don't need to do this, you can just assign the Recurrence to the item, which is of type MyEvent after you've made sure the class has proper support for Recurrence.

If you have more problems, please send us the whole code and we will look at it.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint