Sunday, April 8, 2012

Gantt Chart in adf (Version 1.0)

Gantt Chart :

Gantt Chart is pictorial representation of the data.indeed it is not an easy task to create the Gantt Chart through  EJB business service.

The following definition of  Gantt Chart is  present at oracle site .

"A Gantt chart is a type of horizontal bar graph that you use to plan and track projects. It shows resources or tasks in a time frame with a distinct beginning and end. An ADF Gantt chart component is composed of two regions, one displaying the Gantt chart data in a table, and the other displaying the Gantt chart data graphically with a resizable splitter between the two regions. The table and chart regions share the same data and selection model, supporting and synchronizing scrolling, and expanding and collapsing of rows between the two regions.
At runtime, Gantt charts provide interaction capabilities in the table region to the user such as entering data, expanding and collapsing rows, showing and hiding columns, navigating to a row, and sorting and totaling columns. In the chart region, users can drag a task to a new date, select multiple tasks to create dependencies, and extend the task date. A Gantt chart toolbar is available to support user operations such as changing or filtering the view of the data, and creating, deleting, cutting, copying, and pasting tasks.
Both Gantt chart regions are based on an ADF Faces tree table component."

Basically oracle is supporting follwing three type of gantt chart
1-Project Gantt chart
2-Resource Utilization Gantt chart
3-Scheduling Gantt chart

BTW Gantt Chart contains following  two part.

 1-Table Region -This part  will show the task information in tabular form.This is render the same as af:table therefore it has same behavior.
 which af:table has.it part contains atleast one column.
 2-Gantt Region:This will show the the gantt chart of the data with more other information

 Gantt Chart task is following flavor :
here i just copy paste material whatever is presant in oracle (no comments same as oracle site :)
 1-Normal :The basic task type. It is a plain horizontal bar that shows the start time, end time, and duration of the task.)
 2-Summary: The start and end date for a group of subtasks.
 A summary task cannot be moved or extended. Instead,
 it is the responsibility of the application to execute code to recalculate the start and end date for a summary task when the date of a subtask changes. Summary tasks are available only for the project Gantt chart.
3-Milestone: A specific date in the Gantt chart. There is only one date associated with a milestone task.
A milestone task cannot be extended but it can be moved. A milestone task is available only for the project Gantt chart.
4-Recurring: A task that is repeated in a Gantt chart, each instance with its own start and end date.
Individual recurring tasks can optionally contain a subtype. All other properties of the individual recurring tasks come from the task which they are part of. However, if an individual recurring task has a subtype, this subtype overrides the task type.
5-Split: A task that is split into two horizontal bars, usually linked by a line. The time between the bars represents idle time due to traveling or down time.
6-Scheduled: The basic task type for a scheduling Gantt chart. This task type shows the starting time, ending time, and duration of a task, as well as startup time if one is specified.


IN this post i am going to share you how to create the Project gantt chart.

First following tag is use for creating the Project Gantt

 <dvt:projectGantt endTime="#{pageFlowScope.ganttChart._endDate}"
                          startTime="#{pageFlowScope.ganttChart._startDate}"
                          var="task"
                          filterManager="#{pageFlowScope.filterManagerGanttChart.addFilter}"
                          value="#{pageFlowScope.ganttChart._ganttChartModel}"
                          filterListener="#{pageFlowScope.ganttChart.newFilter}"
                          binding="#{pageFlowScope.ganttChart._ganttChartBinding}"
                          horizontalGridVisible="false" tooltipKeyLabels="Hello"
                          summary="This is Testing Project"
                          initiallyExpandAll="false">
          <f:facet name="major">
            <dvt:timeAxis scale="months"/>
          </f:facet>
          <f:facet name="minor">
            <dvt:timeAxis scale="weeks"/>
          </f:facet>
          <f:facet name="nodeStamp">
            <af:column headerText="Task Id" filterable="true">
              <af:outputText value="#{task.taskId}"/>
            </af:column>
          </f:facet>
          <af:column headerText="Task Name" filterable="true">
            <af:outputText value="#{task.type}"/>
          </af:column>
 </dvt:projectGantt>


 value attribute will  take TreeModel model object.

 For creating the Project Gantt  we required the class which look like following class

package com.prateek.oracle.adf.view.bean;

import com.prateek.oracle.adf.view.bean.DependencyTask;

import com.prateek.oracle.adf.view.bean.SplitTasksBean;

import java.util.Date;
import java.util.List;


public class GanttChartProjectBean {

    public GanttChartProjectBean() {
    }
    // Date. The actual end time for normal and milestone tasks.
    private Date actualEnd;
    //Date. The actual start time for normal and milestone tasks.
    private Date actualStart;
    //Date. Completed through for normal and summary tasks.
    private Date completedThrough;
    //Boolean. Specifies whether or not the task is critical for all tasks.
    private Boolean critical;
    //A list of dependencies for a task. Data object keys for dependencies include:
    //       fromId: The ID of the task where the dependency begins.
    //       toId: The ID of the task where the dependency ends.
    //       type: The type of the dependency. Valid values are start-start, start-finish, finish-finish, finish-start, start-before, start-together, finish-after, and finish-together.
    //  Dependency (node)
    //Date. The end time for all tasks.    (required)
    private Date endTime;
    //String. The first icon associated with the task bar for all tasks.
    //The icon might change depending on other attributes
    private String icon1;
    //String. The second icon associated with the tasks bar for all tasks.
    private String icon2;
    //String. The third icon associated with the tasks bar for all tasks.
    private String icon3;
    //String. The alignment of the icon in the task bar for all tasks. Valid values are left (default),
    //right, inside, start, end, innerLeft, innerRight, innerCenter, innerStart, innerEnd.
    private String iconPlacement;
    //Boolean. Specifies whether or not a node definition is a container.
    private Boolean isContainer;
    //String. The label associated with the task bar for all tasks.
    private String label;
    //String. The alignment of the label in the task bar for all tasks. Valid values are left (default), right, inside, start, end, innerLeft, innerRight, innerCenter, innerStart, innerEnd.
    private String labelPlacement;
    //Integer. Percentage completed for normal and summary tasks.
    private Integer percentComplete;
    //  Recurring tasks (node)
    //  The list of recurring tasks for all tasks.
    //  Split tasks (node)
    //  The list of tasks without a continuous time line for all tasks.
    //Date. The starting time for all tasks.(required)
    private Date startTime;
    //  Subtasks (node)
    //  An optional list of subtasks for all tasks.
    //String. The unique identifier for all tasks.
    private String taskId;
    //Sting. The type of the tasks for all tasks.
    private String type;
    //not in the documnet but still adding because gantt is throwing exception
    private String taskType;
    //split task
    private List<SplitTasksBean> splitTasks;
    private List<DependencyTask> dependencies;


    public void setActualEnd(Date actualEnd) {
        this.actualEnd = actualEnd;
    }

    public Date getActualEnd() {
        return actualEnd;
    }

    public void setActualStart(Date actualStart) {
        this.actualStart = actualStart;
    }

    public Date getActualStart() {
        return actualStart;
    }

    public void setCompletedThrough(Date completedThrough) {
        this.completedThrough = completedThrough;
    }

    public Date getCompletedThrough() {
        return completedThrough;
    }

    public void setCritical(Boolean critical) {
        this.critical = critical;
    }

    public Boolean getCritical() {
        return critical;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setIcon1(String icon1) {
        this.icon1 = icon1;
    }

    public String getIcon1() {
        return icon1;
    }

    public void setIcon2(String icon2) {
        this.icon2 = icon2;
    }

    public String getIcon2() {
        return icon2;
    }

    public void setIcon3(String icon3) {
        this.icon3 = icon3;
    }

    public String getIcon3() {
        return icon3;
    }

    public void setIconPlacement(String iconPlacement) {
        this.iconPlacement = iconPlacement;
    }

    public String getIconPlacement() {
        return iconPlacement;
    }

    public void setIsContainer(Boolean isContainer) {
        this.isContainer = isContainer;
    }

    public Boolean getIsContainer() {
        return isContainer;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

    public void setLabelPlacement(String labelPlacement) {
        this.labelPlacement = labelPlacement;
    }

    public String getLabelPlacement() {
        return labelPlacement;
    }

    public void setPercentComplete(Integer percentComplete) {
        this.percentComplete = percentComplete;
    }

    public Integer getPercentComplete() {
        return percentComplete;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setTaskType(String taskType) {
        this.taskType = taskType;
    }

    public String getTaskType() {
        return taskType;
    }

    public void setDependencies(List<DependencyTask> dependencyTaskList) {
        this.dependencies = dependencyTaskList;
    }

    public List<DependencyTask> getDependencies() {
        return dependencies;
    }

    public void setSplitTasks(List<SplitTasksBean> splitTaskList) {
        this.splitTasks = splitTaskList;
    }

    public List<SplitTasksBean> getSplitTasks() {
        return splitTasks;
    }

}

For getting the TreeModel  object i have written the following code :

    public TreeModel get_ganttChartModel() {
        if (_ganttChartModel == null) {
            List<GanttChartProjectBean> projectList =
                new ArrayList<GanttChartProjectBean>();
            GanttChartProjectBean ganttChartProjectBean =
                new GanttChartProjectBean();
            ganttChartProjectBean.setCritical(false);
            ganttChartProjectBean.setEndTime(GanttChartUtil.addMonth(3));
            ganttChartProjectBean.setStartTime(GanttChartUtil.addMonth(3));
            ganttChartProjectBean.setTaskId("1");
            ganttChartProjectBean.setType("firstwork");
            ganttChartProjectBean.setLabel("Project One ");
            ganttChartProjectBean.setTaskType("Normal");
            ganttChartProjectBean.setLabelPlacement("end");
            ganttChartProjectBean.setPercentComplete(10);
            projectList.add(ganttChartProjectBean);
            _ganttChartModel = new ChildPropertyTreeModel(projectList, null);

        }
        return _ganttChartModel;
    }


   * Here in this method i have just creating the dummy records hence any one can  put their own business logic it may be getting the records from table or using EIB service .


You have option to over ride the default taskbarFormatManager and provide your own custom color and other type of information.


Please open the link to download the whole project

http://www.4shared.com/rar/jAeWL0x1/GanttChart.html

Thanks
Prateek

1 comment:

  1. 2005 Lincoln Aviator AC Compressor
    Very nicely put together post with plenty of superb points. I must say, extremely well done and all the very best moving forward

    ReplyDelete