Class Gantt

java.lang.Object
com.vaadin.flow.component.Component
org.vaadin.tltv.gantt.Gantt
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, Serializable

@Tag("gantt-element") @NpmPackage(value="tltv-gantt-element",version="1.0.30") @NpmPackage(value="tltv-timeline-element",version="1.0.20") @JsModule("tltv-gantt-element/dist/src/gantt-element.js") @CssImport(value="gantt-grid.css", themeFor="vaadin-grid") public class Gantt extends com.vaadin.flow.component.Component implements com.vaadin.flow.component.HasSize
Gantt is a component that shows Gantt chart which is by definition a bar chart that illustrates a project schedule. It's a list of steps where individual step can be divided in multiple substeps. Steps are movable and resizable by mouse/touch devices and API gives control to insert/update/remove steps programmatically. Steps are shown on a timeline which has Day, Week and Hour resolutions. Resolution, date range, language and timezone can be changed with the public API.

Gantt component uses 'tltv-gantt-element' and 'tltv'timeline.element' web components.

See Also:
  • Constructor Details

    • Gantt

      public Gantt()
      Default contructor with default settings. Sets locale to match Component.getLocale().
  • Method Details

    • setupDefaults

      public void setupDefaults()
      Setup component with default settings.
    • setResolution

      public void setResolution(Resolution resolution)
      Set new timeline resolution. Allowed resolutions are Resolution.Hour, Resolution.Day and Resolution.Week.
      Parameters:
      resolution - Resolution enum. Not null.
    • getResolution

      public Resolution getResolution()
      Get current timeline resolution. Default is Resolution.Day.
      Returns:
      Resolution enum
    • setLocale

      public void setLocale(Locale locale)
      Set Locale. Setting locate updates locale of the web component by language tag. It also updates month names, week day names and first day of week based on the Locale.
      Parameters:
      locale - New Locale. Should not be null.
    • getLocale

      public Locale getLocale()
      Return active locale based on the language tag in the web component. This may not be in sync with the application locale if it's changed with setLocale(Locale) or if application locale is changed after constructor is called. Default constructor calls it once with application's locale read with Component.getLocale().
      Overrides:
      getLocale in class com.vaadin.flow.component.Component
      Returns:
      Active Locale
    • setTimeZone

      public void setTimeZone(TimeZone timeZone)
      Parameters:
      timeZone - New TimeZone. Should not be null.
    • getTimeZone

      public TimeZone getTimeZone()
      Get currently active TimeZone based on the zone in the web component. Default is "Europe/London".
      Returns:
      Active TimeZone
    • setStartDate

      public void setStartDate(LocalDate startDate)
      Set start date of the timeline. Call this only with Resolution.Day and Resolution.Week.
      Parameters:
      startDate - Inclusive LocaDate. Not null.
    • setStartDateTime

      public void setStartDateTime(LocalDateTime startDateTime)
      Set start date and time of the timeline. Call this only with Resolution.Hour.
      Parameters:
      startDate - Inclusive LocaDateTime. Not null.
    • getStartDate

      public LocalDate getStartDate()
      Get start date of the timeline based on the web component's start attribute.
      Returns:
      Inclusive LocaDate
    • getStartDateTime

      public LocalDateTime getStartDateTime()
      Get start datetime of the timeline based on the web component's start attribute.
      Returns:
      Inclusive LocaDateTime
    • setEndDate

      public void setEndDate(LocalDate endDate)
      Set end date of the timeline. Call this only with Resolution.Day and Resolution.Week.
      Parameters:
      endDate - Inclusive LocaDate. Not null.
    • setEndDateTime

      public void setEndDateTime(LocalDateTime endDateTime)
      Set end date and time of the timeline. Call this only with Resolution.Hour.
      Parameters:
      endDateTime - Inclusive LocaDateTime. Not null.
    • getEndDate

      public LocalDate getEndDate()
      Get end date of the timeline based on the web component's end attribute.
      Returns:
      Inclusive LocaDate
    • getEndDateTime

      public LocalDateTime getEndDateTime()
      Get end datetime of the timeline based on the web component's end attribute.
      Returns:
      Inclusive LocaDateTime
    • isTwelveHourClock

      public boolean isTwelveHourClock()
      Get value of twelve hour clock boolean flag based on the web component's twelveHourClock attribute. false defaults to 24 hour clock. Affects time formatting in the timeline.
      Returns:
      true when twelveHourClock is enabled and false otherwise
    • setTwelveHourClock

      public void setTwelveHourClock(boolean enabled)
      Set value of twelve hour clock boolean flag to the web component's twelveHourClock attribute.
      Parameters:
      enabled - true when twelveHourClock is enabled and false otherwise
    • setYearRowVisible

      public void setYearRowVisible(boolean visible)
    • isYearRowVisible

      public boolean isYearRowVisible()
      Get year row visibility flag for the timeline based on the web component's yearRowVisible property. Default is true.
    • setMonthRowVisible

      public void setMonthRowVisible(boolean visible)
    • isMonthRowVisible

      public boolean isMonthRowVisible()
      Get month row visibility flag for the timeline based on the web component's monthRowVisible property. Default is true.
    • setMovableSteps

      public void setMovableSteps(boolean enabled)
    • isMovableSteps

      public boolean isMovableSteps()
      Get boolean value of the web component's movableSteps attribute. Attribute controls if steps are movable by user interactions using mouse or touch device. Default is true.
    • setResizableSteps

      public void setResizableSteps(boolean enabled)
    • isResizableSteps

      public boolean isResizableSteps()
      Get boolean value of the web component's resizableSteps attribute. Attribute controls if steps are resizable by user interactions using mouse or touch device. Default is true.
    • setMovableStepsBetweenRows

      public void setMovableStepsBetweenRows(boolean enabled)
    • isMovableStepsBetweenRows

      public boolean isMovableStepsBetweenRows()
      Get boolean value of the web component's movableStepsBetweenRows attribute. Attribute controls if steps are movable between rows by user interactions using mouse or touch device. Default is true. If isMovableSteps() is false, then steps are not movable between rows either even if set to true.
    • addSteps

      public void addSteps(Collection<Step> steps)
      Add new step components based on the given collection of step descriptors. New components are appended at the end.
      Parameters:
      steps - a collection of step descriptor objects for the new components.
    • addSteps

      public void addSteps(Step... steps)
      Add new step components based on the given varargs of step descriptors. New components are appended at the end.
      Parameters:
      steps - a varargs of step descriptor objects for the new components.
    • addSteps

      public void addSteps(Stream<Step> steps)
      Add new step components based on the given stream of step descriptors. New components are appended at the end.
      Parameters:
      steps - a stream of step descriptor objects for the new components.
    • addStep

      public void addStep(Step step)
      Add new step component based on the given step descriptor. New component is appended at the end.
      Parameters:
      step - a step descriptor object for the new component
    • addSubStep

      public void addSubStep(SubStep subStep)
      Add new sub step component based on the given sub step descriptor. New components are appended at the end of the owner step component layout.
      Parameters:
      subStep - a sub step descriptor object for the new component
    • addStep

      public void addStep(int index, Step step)
      Add step component based on the given step descriptor. New component is moved to the given index, moving previous component one index forward. If step already exists based on its UID, then it will be moved. See moveStep(int, GanttStep).
      Parameters:
      index - zero based index for new position
      step - a step descriptor object for the new or existing component
    • moveStep

      public void moveStep(int toIndex, GanttStep anyStep)
      Moves given step or sub step. Same as moveStep(int, Step) or moveSubStep(int, SubStep) depending on which type of a component is being moved based on the UID for the given GanttStep.
      Parameters:
      toIndex - Target zero based index where to move the step
      anyStep - step or sub step descriptor of the moved step
    • moveStep

      public void moveStep(int toIndex, Step step)
      Move given existing step to the given index. Index is based on the state at the moment when method is called. Moved step component is removed and discarded and new step component takes the new position. Existing substep components are moved to the new step component. Context menus and tooltips are recreated for the new step component.
      Parameters:
      toIndex - Target zero based index where to move the step
      step - step descriptor of the moved step
    • moveSubStep

      public void moveSubStep(int toIndex, SubStep subStep)
      Move given existing substep to the given index. Index is based on the state at the moment when method is called. Moved substep component is removed and discarded and new substep component takes the new position as a new children inside the step component at the new index. SubStep.getOwner() is changed to the new owner, and step dates are adjusted to include the substep inside it. Other substep component are not touched. Context menus and tooltips are recreated for the new substep component.
      Parameters:
      toIndex - Target zero based index where to move the substep
      subStep - substep descriptor of the moved substep
    • removeSteps

      public void removeSteps(Collection<Step> steps)
      Removes all given steps if they exists, based on their UIDs.
      Parameters:
      steps - collection of steps, null does nothing
    • removeSteps

      public void removeSteps(Step... steps)
      Removes all given steps if they exists, based on their UIDs.
      Parameters:
      steps - a varargs of steps, null does nothing
    • removeSteps

      public void removeSteps(Stream<Step> steps)
      Removes all given steps looped through the given Stream if they exists, based on their UIDs.
      Parameters:
      steps - Stream of steps, null does nothing
    • removeAnyStep

      public boolean removeAnyStep(String uid)
      Removes Step or sub step if it exists, based on the given UID.
      Parameters:
      uid - Target UID for step or sub step to remove
      Returns:
      boolean true if step or sub step was removed, false otherwise
    • removeAnyStep

      public boolean removeAnyStep(GanttStep step)
      Removes Step or sub step if it exists, based on its UID.
      Parameters:
      step - Target step or sub step to remove
      Returns:
      boolean true if step or sub step was removed, false otherwise
    • removeStep

      public boolean removeStep(Step step)
      Removes given Step if it exists, based on its UID.
      Parameters:
      step - Target step to remove
      Returns:
      boolean true if step was removed, false otherwise
    • getStepElement

      public StepElement getStepElement(String uid)
      Returns StepElement by uid. Includes sub-steps.
    • getStepElementOptional

      public Optional<StepElement> getStepElementOptional(String uid)
      Returns StepElement wrapped in Optional by uid. Includes sub-steps.
    • getStepElements

      public Stream<StepElement> getStepElements()
      Returns StepElement stream excluding sub-steps.
    • getSteps

      public Stream<Step> getSteps()
      Returns Step stream excluding sub-steps.
    • getStepsList

      public List<Step> getStepsList()
      Returns a list of Step objects excluding sub-steps.
    • getFlatStepElements

      public Stream<StepElement> getFlatStepElements()
      Returns StepElement stream of all steps including sub steps.
    • getSubStepElements

      public Stream<StepElement> getSubStepElements(String forStepUid)
      Returns StepElement stream for the given step UID.
      Parameters:
      forStepUid - Target step UID
      Returns:
      StepElement Stream
    • getSubStepElements

      public Stream<StepElement> getSubStepElements()
      Returns StepElement stream of all sub-steps.
    • getSubSteps

      public Stream<SubStep> getSubSteps()
      Returns SubStep stream of all sub-steps.
    • contains

      public boolean contains(String targetUid)
      Returns true if given UID matches with any existing step including sub step.
      Parameters:
      targetUid - Target UID
      Returns:
      boolean true if UID exists
    • contains

      public boolean contains(GanttStep targetStep)
      Returns true if given GanttStep's UID matches with any existing step including sub step.
      Parameters:
      targetStep - Target step or sub step
      Returns:
      boolean true if UID exists
    • contains

      public boolean contains(Step targetStep)
      Returns true if given Step's UID matches with any existing step excluding sub step.
      Parameters:
      targetStep - Target step
      Returns:
      boolean true if step with the UID exists
    • contains

      public boolean contains(SubStep targetSubStep)
      Returns true if given SubStep's UID matches with any existing sub step.
      Parameters:
      targetSubStep - Target sub step
      Returns:
      boolean true if sub step with the UID exists
    • indexOf

      public int indexOf(Step step)
      Returns a zero based index of the given Step.
      Parameters:
      step - Target Step
      Returns:
      zero based index
    • indexOf

      public int indexOf(String stepUid)
      Returns a zero based index of the given UID for a step or sub step. For sub steps index is based on the owner step.
      Parameters:
      stepUid - Target UID
      Returns:
      zero based index
    • getSubStep

      public SubStep getSubStep(String uid)
      Returns SubStep by the UID or null if it doesn't exist.
      Parameters:
      uid - Target UID
      Returns:
      SubStep or null
    • getStep

      public Step getStep(String uid)
      Returns Step by the UID or null if it doesn't exist.
      Parameters:
      uid - Target UID
      Returns:
      Step or null
    • getAnyStep

      public GanttStep getAnyStep(String uid)
      Returns GanttStep by uid. Including sub-steps.
    • updateSubStepsByMovedOwner

      public void updateSubStepsByMovedOwner(String stepUid)
      Updates sub step start and end dates for moved owner step.
      Parameters:
      stepUid - Target owner step UID
    • refresh

      public void refresh(String uid)
      Refresh target step element if it exists.
      Parameters:
      uid - Target step UID
    • ensureUID

      protected <T extends GanttStep> T ensureUID(T step)
      Ensures that given step has UID. If not, then generates one.
    • setWidth

      public void setWidth(String width)
      Specified by:
      setWidth in interface com.vaadin.flow.component.HasSize
    • setHeight

      public void setHeight(String height)
      Specified by:
      setHeight in interface com.vaadin.flow.component.HasSize
    • addGanttClickListener

      public com.vaadin.flow.shared.Registration addGanttClickListener(com.vaadin.flow.component.ComponentEventListener<GanttClickEvent> listener)
    • addStepClickListener

      public com.vaadin.flow.shared.Registration addStepClickListener(com.vaadin.flow.component.ComponentEventListener<StepClickEvent> listener)
    • addStepMoveListener

      public com.vaadin.flow.shared.Registration addStepMoveListener(com.vaadin.flow.component.ComponentEventListener<StepMoveEvent> listener)
    • addStepResizeListener

      public com.vaadin.flow.shared.Registration addStepResizeListener(com.vaadin.flow.component.ComponentEventListener<StepResizeEvent> listener)
    • addDataChangeListener

      public com.vaadin.flow.shared.Registration addDataChangeListener(com.vaadin.flow.component.ComponentEventListener<GanttDataChangeEvent> listener)
    • buildCaptionGrid

      public com.vaadin.flow.component.grid.Grid<Step> buildCaptionGrid(String header)
      Builds a new Grid instance with a single column that renders text based on the step caption. Grid will be kept in sync with the Gantt steps. Instance is available then with getCaptionGrid(). This does not attach component to any layout.
      Parameters:
      header - Header of the column
      Returns:
      A new Grid instance
    • buildCaptionTreeGrid

      public com.vaadin.flow.component.treegrid.TreeGrid<Step> buildCaptionTreeGrid(String header)
      Builds a new TreeGrid instance with a single column that renders text based on the step caption. TreeGrid will be kept in sync with the Gantt steps. Instance is available then with getCaptionGrid(). This does not attach component to any layout.
      Parameters:
      header - Header of the column
      Returns:
      A new TreeGrid instance
    • handleTreeDataAdd

      protected void handleTreeDataAdd(com.vaadin.flow.data.provider.hierarchy.TreeData<Step> treeData, Step step)
    • handleTreeDataMove

      protected void handleTreeDataMove(com.vaadin.flow.data.provider.hierarchy.TreeData<Step> treeData, Step step)
    • expand

      public void expand(Step item)
      Expands all child steps directed by the caption TreeGrid's hierarchical data source.
    • expand

      public void expand(Step item, boolean expandWholeSubTree)
      Expands all child steps directed by the caption TreeGrid's hierarchical data source.
    • expand

      public void expand(Collection<Step> items)
      Expands all child steps directed by the caption TreeGrid's hierarchical data source.
    • expand

      public void expand(Collection<Step> items, boolean expandWholeSubTree)
      Expands all child steps directed by the caption TreeGrid's hierarchical data source.
    • removeCaptionGrid

      public void removeCaptionGrid()
      Remove caption Grid instance if it exists. Grid will not be kept in sync with the Gantt after calling this. This does not detach component from the layout. Synchronized Grid can be created with buildCaptionGrid(String) or buildCaptionTreeGrid(String).
    • getCaptionGrid

      public com.vaadin.flow.component.grid.Grid<Step> getCaptionGrid()
      Get caption Grid instance or null if it's not set. See buildCaptionGrid(String) and buildCaptionTreeGrid(String).
      Returns:
      Grid instance or null
    • getCaptionTreeGrid

      public com.vaadin.flow.component.treegrid.TreeGrid<Step> getCaptionTreeGrid()
      Get caption TreeGrid instance or null if it's not set. See buildCaptionTreeGrid(String).
      Returns:
      Grid instance or null