skip to main content
Programmer's documentation > Developing with the JViews Gantt SDK > Gantt charts > Running the samples
 
Running the samples
Describes how to run the Gantt chart samples supplied with JViews Gantt.
*Gantt chart
*Describes how to construct and display a chart and run the samples.
*Running the sample as an application
*Describes how to run the sample as an application.
*Schedule chart
*Outlines the steps necessary to run the sample application.
*Deploying a Gantt application
*Explains which JAR file contains the JViews Gantt classes.
Gantt chart
The basic steps for using the Gantt chart bean are illustrated in the Activity Chart (SDK) sample. You can find the corresponding source code in:
<installdir>/jviews-gantt/samples/ganttChart/src/ganttChart/GanttExample.java
Most of the code in the Gantt chart sample is for handling the menus and status bar for the application.
The small portion of code necessary to construct and display the chart itself is outlined here:
...
import ilog.views.gantt.*;
import ilog.views.gantt.model.*;
 ...
public class GanttExample extends JRootPane
{
  protected IlvGanttChart gantt;
   ...
  public init(Container container)
   {
    super.init(container);
    // Creates the Gantt chart
    gantt = new IlvGanttChart();
    // Creates the Gantt data model
    IlvGanttModel model = createGanttModel();
    // Sets the data model of the Gantt chart
    gantt.setGanttModel(model);
     ...
    // Add the Gantt chart to the panel
    container.add(gantt, BorderLayout.CENTER);
     ...
  }
   ...
  protected IlvGanttModel createGanttModel()
   {
    IlvGanttModel model = new IlvDefaultGanttModel();
    populateGanttModel(model);
    return model;
   }
 
   protected void populateGanttModel(IlvGanttModel model)
   {
    ... /* Add activities to the data model here */
   }
   ...
 
  public static void main (String[] args)
  {
    JFrame frame = new JFrame("Gantt Chart Example");
    GanttExample ganttChart = new GanttExample();
    ganttChart.init(frame.getContentPane());
 
    // Exit when the main frame is closed.
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter()
    {
      public void windowClosed(WindowEvent e)
      {
        System.exit(0);
      }
    });
 
    // Pack the main frame and make it visible.
    frame.pack();
    frame.setVisible(true);
  }
  ...
}
To run the samples:
1. Make sure that the Ant utility is properly configured. If not, read Starting the samples for instructions on how to configure Ant for JViews Gantt:
2. Go to the directory where the sample is installed and type:
ant run
Running the sample as an application
To run the sample as an application:
*Stage 1 – Importing the Gantt chart packages
*Stage 2 – Creating the Gantt data model
*Stage 3 – Creating the Gantt chart bean instance
*Stage 4 – Binding the Gantt chart to the data model
*Stage 5 – Customizing the chart
*Stage 6 – Adding the Gantt chart to the user interface
Stage 1 – Importing the Gantt chart packages
To import the Gantt chart packages:
1. In <installdir>/jviews-gantt/samples/ganttChart/src/ganttChart/GanttExample.java, import the packages that are common to all the Gantt samples:
import shared.*;
import shared.data.*;
import shared.swing.*;
2. Import the necessary Gantt chart packages:
import ilog.views.gantt.*;
import ilog.views.gantt.action.*;
import ilog.views.gantt.model.*;
import ilog.views.gantt.property.*;
import ilog.views.gantt.swing.*;
3. Import the various Swing and AWT packages necessary to build the rest of the user interface of the samples:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
Both the Gantt chart sample and the Schedule chart sample derive from a common superclass, AbstractGanttExample, that is itself a subclass of AbstractExample. These classes contain the code that is shared between all the Gantt samples. Because the samples are written so that they can be run as an application, AbstractExample extends the Swing class JRootPane and GanttExample provides a static main method to launch the frame window:
public class GanttExample extends AbstractGanttExample
{
  ...
  public static void main(String[] args)
  {
    GanttExample ganttChart = new GanttExample();
    JFrame frame = new ExampleFrame(ganttChart);
    frame.setVisible(true);
  }
  ...
}
Stage 2 – Creating the Gantt data model
The data model should contain resources and reservations that will be displayed by the Gantt chart. Refer to the Connecting to data for detailed information on how to instantiate different Gantt data model implementations and connect to your business data.
To add resources and reservations to the data model:
1. Create a Gantt data model that implements the IlvGanttModel interface.
IlvGanttModel model = ...
2. The Gantt chart and Schedule chart samples use an in-memory data model that is created by the following classes:
*<installdir>/jviews-gantt/samples/ganttChart/src/shared/data/SimpleEngineeringProject.java
*<installdir>/jviews-gantt/samples/scheduleChart/src/shared/data/SimpleEngineeringProject.java
3. The SimpleEngineeringProject class implements a Gantt data model that simulates the scheduling of a typical engineering project. The Gantt chart sample instantiates the data model like this:
IlvGanttModel model = createGanttModel();
...
protected IlvGanttModel createGanttModel() {
  return new SimpleEngineeringProject(chart);
}
Stage 3 – Creating the Gantt chart bean instance
Create an instance of the Gantt chart bean:
*Implement the createChart method using the following code.
protected IlvHierarchyChart createChart()
  {
  return new IlvGanttChart();
}
Stage 4 – Binding the Gantt chart to the data model
Bind the Gantt chart bean to the data model to enables the chart to display the contents of the data model:
*Add the following code to your application:
chart.setGanttModel(model);
Stage 5 – Customizing the chart
The chart is customized in the customizeChart method.
The <installdir>/jviews-gantt/samples/ganttChart/src/ganttChart/GanttExample.java file shows the following basic customizations:
*Several activities are expanded so that all their child activities are initially visible. For example:
chart.expandAllRows(anActivity);
*The width of the table columns are increased. For example:
chart.getTable().getColumn("Name").setPreferredWidth(180);
*The time interval initially displayed by the chart is set:
chart.setVisibleTime(aDate);
chart.setVisibleDuration(new IlvDuration(...));
*Animation of zoom-in and zoom-out is enabled:
chart.setVisibleIntervalAnimationSteps(4);
It is easy to perform other customizations of the chart also.
For example:
1. Change the default height of the displayed rows:
chart.setRowHeight(25);
2. Change the font used to label the horizontal time scale:
chart.setTimeScaleFont(new Font(...));
Stage 6 – Adding the Gantt chart to the user interface
The Gantt chart must now be displayed:
*Add it to the center of the container panel provided as the argument to the init method, which is set to have a BorderLayout attribute:
container.add(gantt, BorderLayout.CENTER);
The container panel will be the contentPane of the frame when the sample is run as an application.
Schedule chart
The basic steps for using the Schedule chart bean are shown in the Resource Chart (SDK) sample. They are almost exactly the same as those for the Gantt chart bean, described in Gantt chart. You can find the corresponding source code in:
<installdir>/jviews-gantt/samples/scheduleChart/src/scheduleChart/ScheduleExample.java
To run the sample as an application:
1. Make sure that the Ant utility is properly configured. If not, read Starting the samples for instructions on how to configure Ant for JViews Gantt:
2. Go to the directory where the sample is installed and type:
ant run
The Schedule chart sample is almost identical to the Gantt chart sample. The main difference is that an IlvScheduleChart object is created instead of an IlvGanttChart object. Here are the key lines of code that are different in the Schedule chart sample:
...
public class ScheduleExample extends AbstractExample
{
  ...
  protected IlvHierarchyChart createChart()
  {
    return new IlvScheduleChart();
  }
 ...
  public static void main(String[] args)
  {
    ScheduleExample scheduleChart = new ScheduleExample();
    JFrame frame = new ExampleFrame(scheduleChart);
    frame.setVisible(true);
  }
 
 ...
}
Deploying a Gantt application
The classes for JViews Gantt are located in the JAR file:
<installdir>/jviews-gantt/lib/jviews-gantt-all.jar.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.