@Override protected Object newInstance(final Class<?> clazz, final Element el, final String attrName, final String attrValue) { if ("predecessor".equals(attrName) == true && XmlConstants.NULL_IDENTIFIER.equals(attrValue) == true) { // Field should set to null. return Status.IGNORE; } if (GanttTask.class.isAssignableFrom(clazz) == true) { final GanttTask ganttObject = getGanttObject(taskTree, ganttChartData, el); if (ganttObject == null) { return new GanttTaskImpl(); // Gantt task not related to a ProjectForge task. } return ganttObject; } else if (Collection.class.isAssignableFrom(clazz) == true) { final GanttTask ganttObject = getGanttObject(taskTree, ganttChartData, el.getParent()); if (ganttObject != null && ganttObject.getChildren() != null) { return ganttObject.getChildren(); } } return null; }
private GanttTaskImpl createActivity(final int durationDays) { final GanttTaskImpl activity = new GanttTaskImpl(); if (durationDays >= 0) { activity.setDuration(new BigDecimal(durationDays)); } activity.setId(counter++); return activity; }
@Test public void getNextId() { GanttTaskImpl root = new GanttTaskImpl(); root.addChild(new GanttTaskImpl(5)); assertEquals(-1, root.getNextId()); root.addChild(new GanttTaskImpl(-1)); assertEquals(-2, root.getNextId()); root.addChild(new GanttTaskImpl(-5)); assertEquals(-6, root.getNextId()); root.addChild(new GanttTaskImpl(-6)); assertEquals(-7, root.getNextId()); } }
@Test public void compareTo() final GanttTaskImpl a1 = new GanttTaskImpl(1).setTitle("B"); assertEquals(0, GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a1)); GanttTaskImpl a2 = new GanttTaskImpl(1).setTitle("A"); assertEquals(0, GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a1)); // Same id a2 = new GanttTaskImpl(2).setTitle("A"); assertTrue("Start date not given, use alphabetical order instead.", GanttUtils.GANTT_OBJECT_COMPARATOR.compare(a1, a2) > 0);
private GanttTaskImpl createGanttObject(final GanttTaskImpl parent, final String workpackageCode, final String title, final String durationDays, final GanttTask dependsOnGanttObject, final GanttRelationType type, final int dependDayOffset) { final GanttTaskImpl node = new GanttTaskImpl(); node.setTitle(title); node.setWorkpackageCode(workpackageCode); node.setDuration(new BigDecimal(durationDays)); node.setVisible(true); if (dependsOnGanttObject != null) { node.setPredecessor(dependsOnGanttObject); } if (type != null) { node.setRelationType(type); } if (dependDayOffset != 0) { node.setPredecessorOffset(dependDayOffset); } if (parent != null) { parent.addChild(node); } node.setPredecessor(dependsOnGanttObject); return node; }
/** * Creates a new GanttTask and copies all fields from the given task (excluding the predecessor and any children). * @param task * @return */ public static final GanttTask convertToGanttObject(final TaskDO task) { final GanttTaskImpl ganttObject = new GanttTaskImpl(); ganttObject.setId(task.getId()); ganttObject.setPredecessorOffset(task.getGanttPredecessorOffset()); ganttObject.setRelationType(task.getGanttRelationType()); ganttObject.setDuration(task.getDuration()); ganttObject.setStartDate(task.getStartDate()); ganttObject.setEndDate(task.getEndDate()); ganttObject.setProgress(task.getProgress()); ganttObject.setType(task.getGanttObjectType()); ganttObject.setDescription(task.getDescription()); ganttObject.setTitle(task.getTitle()); return ganttObject; }
@Test public void hasDuration() { final GanttTask task = new GanttTaskImpl(); assertFalse("duration should be 0.", task.hasDuration()); task.setDuration(BigDecimal.TEN); assertTrue("duration should be 10.", task.hasDuration()); final DayHolder day = new DayHolder(); day.setDate(2010, Calendar.AUGUST, 13); task.setStartDate(day.getDate()); assertTrue("duration should be 10.", task.hasDuration()); task.setDuration(null); assertFalse("duration should be null.", task.hasDuration()); day.add(Calendar.DAY_OF_MONTH, 1); task.setEndDate(day.getDate()); assertTrue("duration expected.", task.hasDuration()); } }
findById(ganttObject, getTask(prefix + "1").getId()) .getStartDate()); findById(ganttObject, getTask(prefix + "1").getId()).addChild(new GanttTaskImpl(-1).setTitle("Child of 1")); findById(ganttObject, getTask(prefix + "1.1").getId()).addChild( new GanttTaskImpl(-2).setTitle("Child of 1.1").addChild(new GanttTaskImpl(-3).setTitle("Grand child of 1.1"))); ganttChartDao.writeGanttObjects(ganttChartDO, ganttObject); xml = transform(prefix, "<ganttObject id='{}'>"