Class GanttChart<R extends Row<?,​?,​?>>

Type Parameters:
R - the type of the rows shown by the Gantt chart (e.g. "Aircraft")
All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class GanttChart<R extends Row<?,​?,​?>>
extends GanttChartBase<R>
A control used to visualize any kind of scheduling data along a timeline. The model data needed by the control consists of rows with activities, links between activities, and layers to group activities together.

The control consists of several children controls:

  • TreeTableView: shown on the left-hand side to display a hierarchical structure of rows
  • GraphicsBase: shown on the right-hand side to display a graphical representation of the model data
  • Timeline: shown above the graphics view. The timeline itself consists of two child controls.
  • Dateline: displays days, weeks, months, years, etc...
  • Eventline: displays various time markers
The screenshot belows shows the initial appearance of an empty Gantt chart control.
Gantt Chart Control

Master / Detail Panes

The Gantt chart uses two MasterDetailPane instances from ControlsFX for the high-level layout. The tree table master detail pane displays the tree table as its detail node. The graphics master detail pane displays a property sheet as its detail node. The property sheet is used at development time and can be replaced with any node by calling GanttChartBase.setDetail(Node). The property sheet displays a lot of properties that are used by the controls, the renderers, the system layers to fine-tune the appearance of the control. Many of them can be changed at runtime.

Standalone vs. Multi- / Dual Gantt Chart

A Gantt chart can be used standalone or inside a MultiGanttChartContainer or DualGanttChartContainer. When used in one of these containers the Position of the Gantt chart becomes important. The control can be the first chart, the last chart, the only chart, or a chart somewhere in the middle. A "first" or "only" chart always displays a timeline. A "middle" or "last" displays a special header (see GanttChartBase.setGraphicsHeader(Node)). The containers are also the reason why the control distinguishes between a timeline (GanttChartBase.getTimeline()) and a master timeline ( GanttChartBase.getMasterTimeline()). The master timeline is the one shown by the "first" chart, while the regular timeline is the one that belongs directly to an individual Gantt chart instance.

Code Example

 import java.time.Duration;
 import java.time.Instant;
 import java.time.temporal.ChronoUnit;

 import javafx.application.Application;
 import javafx.scene.Scene;
 import javafx.stage.Stage;

 import com.flexganttfx.model.GanttChartModel;
 import com.flexganttfx.model.Layer;
 import com.flexganttfx.model.Row;
 import com.flexganttfx.model.activity.MutableActivityBase;
 import com.flexganttfx.model.layout.GanttLayout;
 import com.flexganttfx.view.GanttChart;
 import com.flexganttfx.view.graphics.GraphicsView;
 import com.flexganttfx.view.graphics.renderer.ActivityBarRenderer;
 import com.flexganttfx.view.timeline.Timeline;

 public class TutorialAircraftFlight extends Application {


  class FlightData {
        String flightNo;
        Instant departureTime = Instant.now();
        Instant arrivalTime = Instant.now().plus(Duration.ofHours(6));

        public FlightData(String flightNo, int day) {
                this.flightNo = flightNo;
                departureTime = departureTime.plus(Duration.ofDays(day));
                arrivalTime = arrivalTime.plus(Duration.ofDays(day));
    }
  }

  class Flight extends MutableActivityBase<FlightData> {
        public Flight(FlightData data) {
                setUserObject(data);
                setName(data.flightNo);
                setStartTime(data.departureTime);
                setEndTime(data.arrivalTime);
    }
  }

  class Aircraft extends Row<Aircraft, Aircraft, Flight> {
        public Aircraft(String name) {
                super(name);
    }
  }

  public void start(Stage stage) {
        // Create the root row
        Aircraft root = new Aircraft("Root");
        root.setExpanded(true);

        // Create the Gantt chart
        GanttChart<Aircraft> gantt = new GanttChart<>(new FlightSchedule(new Aircraft("ROOT")));

        Layer flightsLayer = new Layer("Flights");
        gantt.getLayers().add(flightsLayer);

        Aircraft b747 = new Aircraft("B747");
        b747.addActivity(flightsLayer, new Flight(new FlightData("flight1", 1)));
        b747.addActivity(flightsLayer, new Flight(new FlightData("flight2", 2)));
        b747.addActivity(flightsLayer, new Flight(new FlightData("flight3", 3)));

        Aircraft a380 = new Aircraft("A380");
        a380.addActivity(flightsLayer, new Flight(new FlightData("flight1", 1)));
        a380.addActivity(flightsLayer, new Flight(new FlightData("flight2", 2)));
        a380.addActivity(flightsLayer, new Flight(new FlightData("flight3", 3)));

        root.getChildren().setAll(b747, a380);

        Timeline timeline = gantt.getTimeline();
        timeline.showTemporalUnit(ChronoUnit.HOURS, 10);

        GraphicsView<Aircraft> graphics = gantt.getGraphics();
        graphics.setActivityRenderer(Flight.class, GanttLayout.class,
                        new ActivityBarRenderer<>(graphics, "Flight Renderer"));
        graphics.showEarliestActivities();

        Scene scene = new Scene(gantt);
        stage.setScene(scene);
        stage.sizeToScene();
        stage.centerOnScreen();
        stage.show();
  }

  public static void main(String[] args) {
        launch(args);
  }
 
Since:
1.0
  • Property Details

  • Constructor Details

    • GanttChart

      public GanttChart()
      Constructs a new Gantt chart control.
      Since:
      1.0
    • GanttChart

      public GanttChart​(R root)
      Constructs a new Gantt Chart control.
      Parameters:
      root - the root row of the Gantt chart
      Since:
      1.0
  • Method Details

    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class Control
    • displayModeProperty

      public final ObjectProperty<GanttChart.DisplayMode> displayModeProperty()
      A property used to specify the mode in which the Gantt chart will layout its primary views, the table and the graphics. Using this property the application can quickly switch between a standard, table-only, or graphics-only display.
      Since:
      1.0
      See Also:
      getDisplayMode(), setDisplayMode(GanttChart.DisplayMode)
    • setDisplayMode

      public final void setDisplayMode​(GanttChart.DisplayMode mode)
      Sets the value of the displayModeProperty().
      Parameters:
      mode - the new display mode
      Since:
      1.0
    • getDisplayMode

      public final GanttChart.DisplayMode getDisplayMode()
      Returns the value of displayModeProperty().
      Returns:
      the display mode (standard, table only, graphics only)
      Since:
      1.0
    • createTreeTable

      protected TreeTableView<R> createTreeTable()
      Creates the tree table view instance. Applications can override this method to return a customized table.
      Returns:
      a tree table view instance
      Since:
      1.0
    • tableMenuButtonVisibleProperty

      public final BooleanProperty tableMenuButtonVisibleProperty()
      This controls whether a menu button is available when the user clicks in a designated space within the TreeTableView, within which is a check menu item for each column in this table. This menu allows for the user to show and hide all TreeTableColumns easily.
      Since:
      1.0
      See Also:
      isTableMenuButtonVisible(), setTableMenuButtonVisible(boolean)
    • setTableMenuButtonVisible

      public final void setTableMenuButtonVisible​(boolean value)
      Parameters:
      value - if true the menu button will be shown to the user
      Since:
      1.0
    • isTableMenuButtonVisible

      public final boolean isTableMenuButtonVisible()
      Returns the value of tableMenuButtonVisibleProperty().
      Returns:
      true if the table menu button is visible
    • rootProperty

      public final ObjectProperty<R> rootProperty()
      Returns the root row property. The root row will become the root node of the Gantt chart's tree table control on the left-hand side (wrapped inside an instance of type GanttChartTreeItem). Other rows can be added by adding them to the root row or one of its children.
      Since:
      1.0
      See Also:
      getRoot(), setRoot(R)
    • setRoot

      public final void setRoot​(R root)
      Sets a new root on the Gantt chart, which will cause the framework to set a new root of type GanttChartTreeItem on the underlying TreeTableView.
      Parameters:
      root - the new root of the model
      See Also:
      rootProperty()
    • getRoot

      public final R getRoot()
      Returns the root row of the Gantt chart.
      Returns:
      the root row
      Since:
      1.0
    • getRowHeaderColumn

      public final RowHeaderColumn<R> getRowHeaderColumn()
      Returns the row header control used as the first column of the tree table view. The row header displays line numbers, or level numbers, or any arbitrary graphics node.
      Returns:
      the row header (column)
    • createRowHeaderColumn

      protected RowHeaderColumn<R> createRowHeaderColumn()
      Creates the row header column used by the Gantt chart. Applications can override this method to return a customized row header.
      Returns:
      the row header column
      Since:
      1.0
    • getTreeTableScrollBar

      public final ScrollBar getTreeTableScrollBar()
      Returns the scrollbar that is being used for horizontal scrolling operations of the tree table view.
      Returns:
      the horizontal tree table view scrollbar
      Since:
      1.0
    • getTreeTable

      public final TreeTableView<R> getTreeTable()
      Returns the TreeTableView instance that is shown on the left-hand side of the Gantt chart.
      Returns:
      the tree table view
      Since:
      1.0
      See Also:
      createTreeTable()
    • getTreeTableMasterDetailPane

      public org.controlsfx.control.MasterDetailPane getTreeTableMasterDetailPane()
      Returns the primary MasterDetailPane instance that is being used to display the TreeTableView and the ListViewGraphics.
      Returns:
      the primary master detail pane
      Since:
      1.6
    • showTreeTableProperty

      public final BooleanProperty showTreeTableProperty()
      A property used to control whether the tree table view will be shown or not. This node gets shown on the left-hand side of the Gantt chart and dispays a hierarchy (e.g. a resource hierarchy). The tree table view is the detail node of the primary master detail pane (see getTreeTableMasterDetailPane()).
      Since:
      1.0
      See Also:
      isShowTreeTable(), setShowTreeTable(boolean)
    • isShowTreeTable

      public final boolean isShowTreeTable()
      Returns the value of showTreeTableProperty().
      Returns:
      true if the tree table should be shown
      Since:
      1.0
    • setShowTreeTable

      public final void setShowTreeTable​(boolean show)
      Sets the value of showTreeTableProperty().
      Parameters:
      show - if true the tree table becomes visible
      Since:
      1.0
    • rowHeaderTypeProperty

      public final ObjectProperty<GanttChart.RowHeaderType> rowHeaderTypeProperty()
      A property used to store the currently used type of row headers (row number, level number, custom graphics).
      Since:
      1.0
      See Also:
      getRowHeaderType(), setRowHeaderType(GanttChart.RowHeaderType)
    • setRowHeaderType

      public final void setRowHeaderType​(GanttChart.RowHeaderType type)
      Sets the value of rowHeaderTypeProperty().
      Parameters:
      type - the row header type (row number, level number, graphics)
      Since:
      1.0
    • getRowHeaderType

      public final GanttChart.RowHeaderType getRowHeaderType()
      Returns the value of rowHeaderTypeProperty().
      Returns:
      the currently used row header type (line number, level number, custom graphics)
      Since:
      1.0
    • rowHeaderNodeFactoryProperty

      public final ObjectProperty<Callback<R,​Node>> rowHeaderNodeFactoryProperty()
      A property used to store a callback for creating a node that will be placed to the left of each row in the tree table view. This factory will only be invoked if the row header type is set to GanttChart.RowHeaderType.GRAPHIC_NODE.
      Since:
      1.0
      See Also:
      getRowHeaderNodeFactory(), setRowHeaderNodeFactory(Callback)
    • setRowHeaderNodeFactory

      public final void setRowHeaderNodeFactory​(Callback<R,​Node> factory)
      Parameters:
      factory - the factory used for creating the row header nodes
      Since:
      1.0
    • getRowHeaderNodeFactory

      public final Callback<R,​Node> getRowHeaderNodeFactory()
      Returns the value of rowHeaderNodeFactoryProperty().
      Returns:
      the row header nodes factory
    • expandRows

      public final void expandRows()
      Expands all rows inside the Gantt chart. This method will use recursion to find all rows that are parents and to expand them.
      Since:
      1.3
      See Also:
      Row.setExpanded(boolean), expandRowsByOneLevel(), collapseRows(), collapseRowsByOneLevel()
    • expandRowsByOneLevel

      public final void expandRowsByOneLevel()
      Expands the next level of rows inside the Gantt chart. This method will use recursion to find the first rows that are parents and currently not expanded. It will then expand it to make its children visible. Successive calls to this method will eventually show all rows.
      Since:
      1.3
      See Also:
      Row.setExpanded(boolean), expandRows(), collapseRows(), collapseRowsByOneLevel()
    • collapseRows

      public final void collapseRows()
      Collapses all rows inside the Gantt chart. This method will use recursion to find all rows that are parents and to collapse them.
      Since:
      1.3
      See Also:
      Row.setExpanded(boolean), collapseRowsByOneLevel(), expandRows(), expandRowsByOneLevel()
    • collapseRowsByOneLevel

      public final void collapseRowsByOneLevel()
      Collapses the hightest level of rows inside the Gantt chart that is currently being used. Successive calls to this method will eventually close the entire tree.
      Since:
      1.3
      See Also:
      Row.setExpanded(boolean), expandRows(), collapseRows(), collapseRowsByOneLevel()
    • resizeColumns

      public final void resizeColumns()
      This method will resize all columns in the tree table view to ensure that the content of all cells will be completely visible. Note: this is a very expensive operation and should only be used when the number of rows is small.
      Since:
      1.3
      See Also:
      resizeColumn(TreeTableColumn, int)
    • resizeColumns

      public final void resizeColumns​(int maxRows)
      This method will resize all columns in the tree table view to ensure that the content of all cells will be completely visible. Note: this is a very expensive operation and should only be used with a small number of rows.
      Parameters:
      maxRows - the maximum number of rows that will be considered for the width calculations
      Since:
      1.3
      See Also:
      resizeColumn(TreeTableColumn, int)
    • resizeColumn

      public final void resizeColumn​(TreeTableColumn<R,​?> column)
      This method will resize the given column in the tree table view to ensure that the content of the column cells will be completely visible. Note: this is a very expensive operation and should only be used when the number of rows is small.
      Parameters:
      column - the column that will be resized
      Since:
      1.3
      See Also:
      resizeColumn(TreeTableColumn, int)
    • resizeColumn

      public final void resizeColumn​(TreeTableColumn tc, int maxRows)
      This method will resize the given column in the tree table view to ensure that the content of the column cells will be completely visible. Note: this is a very expensive operation and should only be used when the number of rows is small.
      Parameters:
      tc - the column that will be resized
      maxRows - the maximum number of rows that will be evaluated for the width calculation
      Since:
      1.3
      See Also:
      resizeColumn(TreeTableColumn, int)