Project's calculation modes

Project Calculation Modes

Aspose.Tasks for Java API provides three project calculation modes which define how values of dependent properties are calculated when the value of a property is set. These calculation modes are:

This examples below shows the usage of each of these with the help of code samples.

Project Calculation Mode - None

 1// Create empty project and set calculation mode to None
 2Project project = new Project();
 3project.setCalculationMode(CalculationMode.None);
 4
 5// Add a new task
 6Task task = project.getRootTask().getChildren().add("Task");
 7
 8Date minDate = new GregorianCalendar(1, Calendar.JANUARY, 1).getTime();
 9
10// Note that even ids were not calculated
11System.out.println("Task Id Equals 0 : " + task.get(Tsk.ID).equals(0));
12System.out.println("Task Start Equals 01/01/0001 : " + task.get(Tsk.START).equals(minDate));
13System.out.println("Task Finish Equals 01/01/0001 : " + task.get(Tsk.FINISH).equals(minDate));
14System.out.println("Task Duration Equals 0 mins : " + task.get(Tsk.DURATION).toString().equals("0 mins"));
15
16// Set duration property
17task.set(Tsk.DURATION, project.getDuration(2, TimeUnitType.Day));
18System.out.println("Task Duration Equals 2 days : " + task.get(Tsk.DURATION).toString().equals("2 days"));
19System.out.println("Task Start Equals 01/01/0001 : " + task.get(Tsk.START).equals(minDate));
20System.out.println("Task Finish Equals 01/01/0001 : " + task.get(Tsk.FINISH).equals(minDate));

Project Calculation Mode - Manual

 1// Create empty project and set calculation mode to Manual
 2Project project = new Project();
 3project.setCalculationMode(CalculationMode.Manual);
 4
 5// Set project start date and add new tasks
 6project.set(Prj.START_DATE, new GregorianCalendar(2015, Calendar.APRIL, 15).getTime());
 7Task task1 = project.getRootTask().getChildren().add("Task 1");
 8Task task2 = project.getRootTask().getChildren().add("Task 2");
 9
10// The necessary properties are set in manual mode
11Date start = new GregorianCalendar(2015, Calendar.APRIL, 15, 8, 0, 0).getTime();
12Date finish = new GregorianCalendar(2015, Calendar.APRIL, 15, 17, 0, 0).getTime();
13System.out.println("Task1 Id Equals 1 : " + task1.get(Tsk.ID).equals(1));
14System.out.println("Task1 Start Equals 15/04/2015 08:00 AM : " + task1.get(Tsk.START).equals(start));
15System.out.println("Task1 Finish Equals 15/04/2015 05:00 PM : " + task1.get(Tsk.FINISH).equals(finish));
16System.out.println("Task1 Duration Equals 1 day : " + task1.get(Tsk.DURATION).toString().equals("1 day"));
17System.out.println("Task2 Start Equals 15/04/2015 08:00 AM : " + task2.get(Tsk.START).equals(start));
18System.out.println("Task2 Finish Equals 15/04/2015 05:00 PM : " + task2.get(Tsk.FINISH).equals(finish));
19System.out.println("Task2 Duration Equals 1 day : " + task2.get(Tsk.DURATION).toString().equals("1 day"));
20
21// When we link two tasks together their dates are not recalculated in manual mode
22TaskLink link = project.getTaskLinks().add(task1, task2, TaskLinkType.FinishToStart);
23
24// Task 2 Start has not been changed
25System.out.println("Task1 Start Equals Task2 Start : " + task1.get(Tsk.START).equals(task2.get(Tsk.START)));
26System.out.println("Task1 Finish Equals Task2 Finish : " + task1.get(Tsk.FINISH).equals(task2.get(Tsk.FINISH)));

Project Calculation Mode - Automatic

 1// Create empty project and set calculation mode to Automatic
 2Project project = new Project();
 3project.setCalculationMode(CalculationMode.Automatic);
 4
 5// Set project start date and add new tasks
 6project.set(Prj.START_DATE, new GregorianCalendar(2015, Calendar.APRIL, 15).getTime());
 7Task task1 = project.getRootTask().getChildren().add("Task 1");
 8Task task2 = project.getRootTask().getChildren().add("Task 2");
 9
10// Link tasks
11TaskLink link = project.getTaskLinks().add(task1, task2, TaskLinkType.FinishToStart);
12
13// Verify dates have been recalculated
14Calendar cal = Calendar.getInstance();
15cal.setTime(task1.get(Tsk.START));
16cal.add(Calendar.DATE, 1);
17Date task1StartPlusOneDay = cal.getTime();
18System.out.println("Task1 Start + 1 Equals Task2 Start : " + task1StartPlusOneDay.equals(task2.get(Tsk.START)));
19
20cal.setTime(task1.get(Tsk.FINISH));
21cal.add(Calendar.DATE, 1);
22Date task1FinishPlusOneDay = cal.getTime();
23System.out.println("Task1 Finish + 1 Equals Task2 Finish : " + task1FinishPlusOneDay.equals(task2.get(Tsk.FINISH)));
24
25System.out.println("RootTask Finish Equals Task2 Finish : " + project.getRootTask().get(Tsk.FINISH).equals(task2.get(Tsk.FINISH)));
26System.out.println("Project Finish Date Equals Task2 Finish : " + project.get(Prj.FINISH_DATE).equals(task2.get(Tsk.FINISH)));
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.