How to add day types in MPJX?

101 views Asked by At

I'm currently developing a planner generator using MPJX. I just want to add some day types in the calendar. Can someone please provide some code example on how to do it?

PS: I already know how to create data type but when I run the program, all the data types I created didn't show in the .planner file.

    ProjectCalendar projectCalendar = file.addDefaultBaseCalendar();
    Calendars calendars = new Calendar()
    DayTypes dayTypes = new DayTypes();

    DayType halfDay = new DayType();
    halfDay.setId("3");
    halfDay.setName("Half Day");
    halfDay.setDescription("Half Day");
    dayTypes.getDayType().add(halfDay);

    DayType scrumMeeting = new DayType();
    scrumMeeting.setId("4");
    scrumMeeting.setName("Scrum Meeting");
    scrumMeeting.setDescription("Scrum Meeting");
    dayTypes.getDayType().add(scrumMeeting);

    calendars.setDayTypes(dayTypes);
1

There are 1 answers

0
Jon Iles On

Your example code is conflating two distinct sets of classes.

This code is fine - this is the standard MPXJ API.

ProjectFile file = /* code here to create/read project file */;
file.addDefaultCalendar();

The remaining code in your example...

Calendars calendars = new Calendar()
DayTypes dayTypes = new DayTypes();
DayType halfDay = new DayType();
// etc...

... is using classes from the net.sf.mpxj.planner.schema package, which is implementation detail internal to MPXJ... not indended for direct use. (The classes in there are generated by JAXB and used to marshall/unmarshall the Planner XML file).