Module com.flexganttfx.model
Package com.flexganttfx.model
Class Row<P extends Row<?,?,?>,C extends Row<?,?,?>,A extends Activity>
- java.lang.Object
-
- com.flexganttfx.model.Row<P,C,A>
-
- Type Parameters:
P
- the type of the parent row (example: row is of type "Building" and parent type is "Factory" to express that the factory consists of several buildings).C
- the type of the children rows (example: row is of type "Building" and children type is "Machine" to express that the building houses several machines).A
- the type of the activities shown in this row (example: row is of type "Building", activities are "ProductionOrders" that are executed in this building).
public abstract class Row<P extends Row<?,?,?>,C extends Row<?,?,?>,A extends Activity> extends Object
A row object is used to store the activities found on a row of the Gantt chart. These activities are not stored directly on the row but in an activity repository (seegetRepository()
). The default repository is of typeIntervalTreeActivityRepository
and can be replaced by callingsetRepository(ActivityRepository)
. Activities can be placed on lines within the row. The row delegates this work to aLinesManager
. The default manager is of typeEqualLinesManager
. To replace the manager simply callsetLinesManager(LinesManager)
.Code Example
public class Aircraft extends Row<Fleet, CrewMember, Flight> { }
This now allows you to call:Aircraft aircraft = new Aircraft(); ... Fleet fleet = aircraft.getParent(); List<CrewMember> crew = aircraft.getChildren();
Lazy Loading
Simply override theisLeaf()
method to control whether a row is a parent row or not. Then listen to changes of the expanded property to load the children when the user toggles the expansion state.static class HelloLazyRow extends Row<HelloLazyRow, HelloLazyRow, Activity> { public HelloLazyRow(String name) { super(name); expandedProperty().addListener(it -> loadChildrenLazily()); } @Override public boolean isLeaf() { return false; } private void loadChildrenLazily() { getChildren().add(new HelloLazyRow("Child 1")); getChildren().add(new HelloLazyRow("Child 2")); ... getChildren().add(new HelloLazyRow("Child N")); } }
- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static double
DEFAULT_ROW_HEIGHT
The default height of a row (24 pixels).
-
Constructor Summary
Constructors Constructor Description Row()
Constructs a new row with anIntervalTreeActivityRepository
and anEqualLinesManager
.Row(String name)
Constructs a new row with anIntervalTreeActivityRepository
and anEqualLinesManager
and the given name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addActivity(Layer layer, A activity)
Adds the given activity for the given layer to this row.void
clearActivities()
Removes all activities from the row.void
clearActivities(Layer layer)
Removes all activities on the given layer from the row.BooleanProperty
expandedProperty()
The property used to store the expansion state of the row.ObservableList<Calendar<?>>
getCalendars()
Returns a list of calendars attached to this row.ObservableList<C>
getChildren()
Returns the list of children of this row.Instant
getEarliestTimeUsed()
Returns the earliest time used by the row.double
getHeight()
Returns the value of theheightProperty()
.Instant
getLatestTimeUsed()
Returns the latest time used by the row.Layout
getLayout()
Returns the value of thelayoutProperty()
.int
getLineCount()
Returns the value of thelineCountProperty()
.double
getLineHeight(int lineIndex)
Returns the height of the given inner line.int
getLineIndex(A activity)
Returns the line index for the given activity.Layout
getLineLayout(int lineIndex)
Returns a line-specific layout for the given line.double
getLineLocation(int lineIndex)
Returns the location of the given inner line.LinesManager<A>
getLinesManager()
Returns the value oflinesManagerProperty()
.double
getMaxHeight()
Returns the value ofmaxHeightProperty()
.double
getMinHeight()
Returns the value of theminHeightProperty()
.String
getName()
Returns the value of thenameProperty()
.P
getParent()
The parent of this row.Row[]
getPath()
Returns the path to this row, for example [ROOT, Parent1, Parent2, this].ObservableMap<Object,Object>
getProperties()
Returns an observable map of properties on this row.ActivityRepository<A>
getRepository()
Returns the value of therepositoryProperty()
.Object
getUserObject()
Returns the value ofuserObjectProperty()
.ZoneId
getZoneId()
Returns the value of thezoneIdProperty()
.boolean
hasChildren(Predicate predicate)
Checks whether the given row has any child rows (no matter how deep) that fulfill the given predicate.boolean
hasProperties()
Tests if the row has properties.DoubleProperty
heightProperty()
The property used to store the height of the row.boolean
isExpanded()
Returns the value of theexpandedProperty()
.boolean
isLeaf()
A row is a leaf in the tree table view on the left-hand side of the Gantt chart if it has no children.boolean
isShowing()
Returns the value ofshowingProperty()
.ObjectProperty<Layout>
layoutProperty()
The property used to store the layout used for laying out the activities that are directly associated with the row (and not on an inner line).ReadOnlyBooleanProperty
leafProperty()
Represents the TreeItem leaf property, which is true if the TreeItem has no children.IntegerProperty
lineCountProperty()
The property used to keep track of the number of inner lines shown by the row.ObjectProperty<LinesManager<A>>
linesManagerProperty()
The property used to store theLinesManager
instance for this row.DoubleProperty
maxHeightProperty()
The property used to store the maximum height of the row.DoubleProperty
minHeightProperty()
The property used to store the minimum height of the row.StringProperty
nameProperty()
The property used to store the name of the row.ReadOnlyObjectProperty<P>
parentProperty()
Returns a read-only property used to store the parent row of this row.void
removeActivity(Layer layer, A activity)
Removes the given activity from the given layer from this row.ObjectProperty<ActivityRepository<A>>
repositoryProperty()
The property used to store the activity repository for the row.void
setExpanded(boolean expanded)
Sets the value of theexpandedProperty()
.void
setHeight(double height)
Sets the value of theheightProperty()
.void
setLayout(Layout layout)
Sets the value of thelayoutProperty()
.void
setLineCount(int count)
Sets the value of thelineCountProperty()
.void
setLinesManager(LinesManager<A> manager)
Sets the value oflinesManagerProperty()
.void
setMaxHeight(double height)
Sets the value of themaxHeightProperty()
.void
setMinHeight(double height)
Sets a new value for theminHeightProperty()
.void
setName(String name)
Sets the value of thenameProperty()
.void
setRepository(ActivityRepository<A> repository)
Sets the value of therepositoryProperty()
.void
setUserObject(Object obj)
Sets the value ofuserObjectProperty()
.void
setZoneId(ZoneId zoneId)
Sets the value of thezoneIdProperty()
.ReadOnlyBooleanProperty
showingProperty()
The property used to express whether a row is currently showing in the view or not.String
toString()
ObjectProperty<Object>
userObjectProperty()
The property used to store a row-specific user object.ObjectProperty<ZoneId>
zoneIdProperty()
The property used to store the zone ID for this row.
-
-
-
Constructor Detail
-
Row
public Row()
Constructs a new row with anIntervalTreeActivityRepository
and anEqualLinesManager
.- Since:
- 1.0
-
Row
public Row(String name)
Constructs a new row with anIntervalTreeActivityRepository
and anEqualLinesManager
and the given name.- Parameters:
name
- the name of the row (e.g. "Building 1")- Since:
- 1.0
-
-
Method Detail
-
getProperties
public final ObservableMap<Object,Object> getProperties()
Returns an observable map of properties on this row.- Returns:
- an observable map of properties on this row
-
hasProperties
public final boolean hasProperties()
Tests if the row has properties.- Returns:
- true if node has properties.
-
getParent
public final P getParent()
The parent of this row. Each row can have only one parent. If a row has no parent, it represents a root in the tree model.- Returns:
- the parent of this row, or null if the row has no parent.
- Since:
- 1.0
-
parentProperty
public final ReadOnlyObjectProperty<P> parentProperty()
Returns a read-only property used to store the parent row of this row.- Returns:
- the property used for storing the parent row
- Since:
- 1.0
-
getPath
public final Row[] getPath()
Returns the path to this row, for example [ROOT, Parent1, Parent2, this].- Returns:
- the path to this row
- Since:
- 1.0
-
getChildren
public final ObservableList<C> getChildren()
Returns the list of children of this row.- Returns:
- the children
- Since:
- 1.0
-
hasChildren
public boolean hasChildren(Predicate predicate)
Checks whether the given row has any child rows (no matter how deep) that fulfill the given predicate.- Parameters:
predicate
- the test to perform- Returns:
- true if the row has any children where the predicate returns true
-
isLeaf
public boolean isLeaf()
A row is a leaf in the tree table view on the left-hand side of the Gantt chart if it has no children. This method may of course be overridden by subclasses to support alternate means of defining how a row may be a leaf, but the general premise is the same: a leaf can not be expanded by the user, and as such will not show a disclosure node or respond to expansion requests.- Returns:
- true if the row is a leaf (has no children rows)
- Since:
- 1.3
-
leafProperty
public final ReadOnlyBooleanProperty leafProperty()
Represents the TreeItem leaf property, which is true if the TreeItem has no children.- Returns:
- a property for determining if the row is a leaf row
- Since:
- 1.3
-
expandedProperty
public final BooleanProperty expandedProperty()
The property used to store the expansion state of the row. The value of this property is needed for controlling the state of the tree items that will be created for the tree table view control on the left-hand side of the Gantt chart.- Returns:
- the expanded property
- Since:
- 1.0
-
setExpanded
public final void setExpanded(boolean expanded)
Sets the value of theexpandedProperty()
.- Parameters:
expanded
- the new value of the expanded property- Since:
- 1.0
-
isExpanded
public final boolean isExpanded()
Returns the value of theexpandedProperty()
.- Returns:
- true if the row is expanded
- Since:
- 1.0
-
showingProperty
public final ReadOnlyBooleanProperty showingProperty()
The property used to express whether a row is currently showing in the view or not. This information can be useful when deciding whether a row needs to update its activities or not, for example in a lazy-loading scenario.- Returns:
- the showing property
- Since:
- 1.0
-
isShowing
public final boolean isShowing()
Returns the value ofshowingProperty()
.- Returns:
- true if the row is currently showing in the UI
- Since:
- 1.0
-
layoutProperty
public final ObjectProperty<Layout> layoutProperty()
The property used to store the layout used for laying out the activities that are directly associated with the row (and not on an inner line).- Returns:
- the row layer property
- Since:
- 1.0
- See Also:
getLineLayout(int)
-
getLayout
public final Layout getLayout()
Returns the value of thelayoutProperty()
.- Returns:
- the layout of the row
- Since:
- 1.0
-
setLayout
public final void setLayout(Layout layout)
Sets the value of thelayoutProperty()
.- Parameters:
layout
- the new row layout- Since:
- 1.0
-
repositoryProperty
public final ObjectProperty<ActivityRepository<A>> repositoryProperty()
The property used to store the activity repository for the row. A repository is used to lookup the activities for a given time interval that needs to be shown on the row.- Returns:
- the repository property
- Since:
- 1.0
-
getRepository
public final ActivityRepository<A> getRepository()
Returns the value of therepositoryProperty()
.- Returns:
- the activity repository of the row
- Since:
- 1.0
-
setRepository
public final void setRepository(ActivityRepository<A> repository)
Sets the value of therepositoryProperty()
.- Parameters:
repository
- the new repository to use- Since:
- 1.0
-
getEarliestTimeUsed
public final Instant getEarliestTimeUsed()
Returns the earliest time used by the row. This is a convenience method delegating toActivityRepository.getEarliestTimeUsed()
.- Returns:
- the earliest time used by the row / by the activities of the row / earliest start time of any activity on the row
- Since:
getLatestTimeUsed()
, 1.0
-
getLatestTimeUsed
public final Instant getLatestTimeUsed()
Returns the latest time used by the row. This is a convenience method delegating toActivityRepository.getLatestTimeUsed()
.- Returns:
- the latest time used by the row / by the activities of the row / earliest start time of any activity on the row
- Since:
getEarliestTimeUsed()
, 1.0
-
nameProperty
public final StringProperty nameProperty()
The property used to store the name of the row.- Returns:
- the name property
- Since:
- 1.0
-
getName
public final String getName()
Returns the value of thenameProperty()
.- Returns:
- the name of the row
- Since:
- 1.0
-
setName
public final void setName(String name)
Sets the value of thenameProperty()
.- Parameters:
name
- the new name of the row- Since:
- 1.0
-
heightProperty
public final DoubleProperty heightProperty()
The property used to store the height of the row.- Returns:
- the row height property
- Since:
- 1.0
-
setHeight
public final void setHeight(double height)
Sets the value of theheightProperty()
.- Parameters:
height
- the new height of the row- Since:
- 1.0
-
getHeight
public final double getHeight()
Returns the value of theheightProperty()
.- Returns:
- the value of the height property
- Since:
- 1.0
-
minHeightProperty
public final DoubleProperty minHeightProperty()
The property used to store the minimum height of the row. The user will not be able to resize the row to anything smaller than the value of this property.- Returns:
- the minimum height property
- Since:
- 1.0
-
setMinHeight
public final void setMinHeight(double height)
Sets a new value for theminHeightProperty()
.- Parameters:
height
- the new minimum height- Since:
- 1.0
-
getMinHeight
public final double getMinHeight()
Returns the value of theminHeightProperty()
.- Returns:
- the minimum height of the row
- Since:
- 1.0
-
maxHeightProperty
public final DoubleProperty maxHeightProperty()
The property used to store the maximum height of the row. The user will not be able to resize the row to anything larger than the value of this property.- Returns:
- the maximum height property
- Since:
- 1.0
-
setMaxHeight
public final void setMaxHeight(double height)
Sets the value of themaxHeightProperty()
.- Parameters:
height
- the maximum height of the row- Since:
- 1.0
-
getMaxHeight
public final double getMaxHeight()
Returns the value ofmaxHeightProperty()
.- Returns:
- the maximum height of the row
- Since:
- 1.0
-
userObjectProperty
public final ObjectProperty<Object> userObjectProperty()
The property used to store a row-specific user object.- Returns:
- the user object property
- Since:
- 1.0
-
getUserObject
public final Object getUserObject()
Returns the value ofuserObjectProperty()
.- Returns:
- the user object associated with this row
- Since:
- 1.0
-
setUserObject
public final void setUserObject(Object obj)
Sets the value ofuserObjectProperty()
.- Parameters:
obj
- the new user object- Since:
- 1.0
-
linesManagerProperty
public final ObjectProperty<LinesManager<A>> linesManagerProperty()
The property used to store theLinesManager
instance for this row. The lines manager is used to control the layout of inner lines and the placement of activities on these lines.- Returns:
- the lines manager property
- Since:
- 1.0
-
getLinesManager
public final LinesManager<A> getLinesManager()
Returns the value oflinesManagerProperty()
.- Returns:
- the lines manager for this row
- Since:
- 1.0
-
setLinesManager
public final void setLinesManager(LinesManager<A> manager)
Sets the value oflinesManagerProperty()
.- Parameters:
manager
- the new lines manager- Since:
- 1.0
-
zoneIdProperty
public final ObjectProperty<ZoneId> zoneIdProperty()
The property used to store the zone ID for this row. Each row can be placed in a different time zone.- Returns:
- the zone ID property
- Since:
- 1.0
-
getZoneId
public final ZoneId getZoneId()
Returns the value of thezoneIdProperty()
.- Returns:
- the zone ID of this row
- Since:
- 1.0
-
setZoneId
public final void setZoneId(ZoneId zoneId)
Sets the value of thezoneIdProperty()
.- Parameters:
zoneId
- the new zone ID for this row- Since:
- 1.0
-
getCalendars
public final ObservableList<Calendar<?>> getCalendars()
Returns a list of calendars attached to this row. Calendars directly attached to a row can be used to visualize row-specific information, for example "resource availability".- Returns:
- a list of row-specific calendars
- Since:
- 1.0
-
lineCountProperty
public final IntegerProperty lineCountProperty()
The property used to keep track of the number of inner lines shown by the row.- Returns:
- the line count property
- Since:
- 1.0
-
setLineCount
public final void setLineCount(int count)
Sets the value of thelineCountProperty()
.- Parameters:
count
- the new line count for the row- Since:
- 1.0
-
getLineCount
public final int getLineCount()
Returns the value of thelineCountProperty()
.- Returns:
- the line count of the row
- Since:
- 1.0
-
addActivity
public final void addActivity(Layer layer, A activity)
Adds the given activity for the given layer to this row. This method delegates toMutableActivityRepository.addActivity(ActivityRef)
.- Parameters:
layer
- the layer where the activity will be displayedactivity
- the activity that will be added- Since:
- 1.0
- See Also:
MutableActivityRepository.addActivity(ActivityRef)
-
removeActivity
public final void removeActivity(Layer layer, A activity)
Removes the given activity from the given layer from this row.- Parameters:
layer
- the layer from which to remove the activityactivity
- the activity to remove- Since:
- 1.0
- See Also:
MutableActivityRepository.removeActivity(ActivityRef)
-
clearActivities
public final void clearActivities()
Removes all activities from the row.- Since:
- 1.0
- See Also:
MutableActivityRepository.clearActivities()
-
clearActivities
public final void clearActivities(Layer layer)
Removes all activities on the given layer from the row.- Parameters:
layer
- the layer from which to remove all activities- Since:
- 1.0
- See Also:
MutableActivityRepository.clearActivities(Layer)
-
getLineIndex
public final int getLineIndex(A activity)
Returns the line index for the given activity. This is a convenience method delegating toLinesManager.getLineIndex(Activity)
.- Parameters:
activity
- the activity for which to return a line index- Returns:
- the line index for the given activity
- Since:
- 1.0
-
getLineLocation
public final double getLineLocation(int lineIndex)
Returns the location of the given inner line. The value returned is usually between 0 andgetHeight()
.- Parameters:
lineIndex
- the index of the line for which to return a location- Returns:
- the line location y-coordinate
- Since:
- 1.0
-
getLineHeight
public final double getLineHeight(int lineIndex)
Returns the height of the given inner line. The value returned is usually between 0 andgetHeight()
.- Parameters:
lineIndex
- the index of the line for which to return a height- Returns:
- the height of the line
- Since:
- 1.0
-
getLineLayout
public final Layout getLineLayout(int lineIndex)
Returns a line-specific layout for the given line.- Parameters:
lineIndex
- the index of the line- Returns:
- the line layout
- Since:
- 1.0
-
-