skip to main content
Gantt > Programmer's documentation > Developing with the JViews Gantt SDK > Connecting to data > Connecting to data in-memory
 
Connecting to data in-memory
Explains how to connect and populate the data model using data in-memory.
*When to use data in-memory
*Explains the main use for data in-memory and describes how to connect to it.
*Activities and resources
*Describes the stages necessary to populate your data model with activities and resources.
*Populating the data model
*Describes how to populate your data model with activities and resources.
*Manipulating activities and resources
*Describes the methods available to manipulate activities and resources within the data model.
*Activity and resource factories
*Explains how create activities and resources based on the factory design pattern.
*Constraints
*Explains the associations between the classes needed to model constraints, and the prerequisite to adding a constraint and the constraint factory.
*Reservations
*Explains the associations between the classes needed to model reservations, and the prerequisite to adding a reservation and the reservation factory.
When to use data in-memory
This access mode is often used to supply data for testing dynamic styling. You can use it to simulate situations where you have designed a change in the representation of the business data to flag specific cases, such as the crossing of a threshold. You can find such test data in:
<installdir>/jviews-gantt/samples/ganttChart/src/shared/data/SimpleEngineeringProject.java
Connecting to data in-memory implies populating the data model. You can do so before or after a chart has been bound to it.
*If you do it before binding a chart, the initial data will be immediately displayed by the chart when it binds to the data model.
*If you do it after binding a chart, the chart will update dynamically to reflect the new data in the data model.
For better performance, the recommended procedure consists in populating your data model before the chart is bound, especially if you have a large data set.
You populate the data model with:
*Activities and resources
*Constraints
*Reservations
You can clear all entities from the data model by using the clear() method defined in the IlvAbstractGanttModel base class. This will depopulate all activities, resources, constraints, and reservations from the data model.
Activities and resources
An activity is a task that must be completed in the schedule. One or more resources can be allocated to an activity to enable its completion. Activities are defined by the IlvActivity interface and resources by the IlvResource interface. Both are stored in a hierarchical structure within the data model and are subinterfaces of the IlvHierarchyNode interface.
Each activity can have 0, 1, or more child activities. Similarly, each resource can have 0, 1, or more child resources. An activity or resource with at least one child is called a parent activity or parent resource. Conversely, an activity or resource with no children is called a leaf activity or leaf resource. The top level of hierarchical trees of activities and resources is called the root activity and root resource. Each activity and resource in the data model is a child of its parent, except for the roots, which have no parent.
The following figure shows the associations between the classes needed to model constraints.
Populating the data model
Explains how to set IlvActivity and IlvResource instances to an IlvGanttModel object.
To populate your data model with activities and resources:
1. Populate a data model with activities by establishing the root IlvActivity object:
IlvGanttModel ganttModel = new IlvDefaultGanttModel();
IlvActivity rootActivity = new IlvGeneralActivity(...);
ganttModel.setRootActivity(rootActivity);
2. Add more activities to the data model using either of the following IlvGanttModel methods:
*void addActivity(IlvActivity newActivity, IlvActivity parent)
*void addActivity(IlvActivity newActivity, IlvActivity parent, int)
For example, here you add a child activity to the root activity that was created in the data model:
IlvActivity childActivity = new IlvGeneralActivity(...);
ganttModel.addActivity(childActivity, rootActivity);
3. Populate the data model with resources by establishing the root IlvResource object:
IlvGanttModel ganttModel = new IlvDefaultGanttModel();
IlvResource rootResource = new IlvGeneralResource(...);
ganttModel.setRootResource(rootResource);
4. Add more resources to the data model using either of the following IlvGanttModel methods:
*void addResource(IlvResource newResource, IlvResource parent)
*void addResource(IlvResource newResource, IlvResource parent, int)
For example, here you add a child resource to the root resource just added to the data model:
IlvResource childResource = new IlvGeneralResource(...);
ganttModel.addResource(childResource, rootResource);
Manipulating activities and resources
By continuing to add activities and resources in the manner described in Populating the data model, you populate the Gantt data model with your scheduling data. The following table shows the IlvGanttModel methods that allow you to manipulate the activities and resources within the data model:
Activities
Resources
addActivity (two signatures)
addResource (two signatures)
getRootActivity
getRootResource
moveActivity
moveResource
removeActivity(two signatures)
removeResource (two signatures)
setRootActivity
setRootResource
Activity and resource factories
The Gantt chart and Schedule chart beans provide a flexible way to create activities and resources, based on the factory design pattern.
The IlvHierarchyChart class, which is the superclass of both IlvGanttChart and IlvScheduleChart, contains an activity factory defined by the IlvActivityFactory interface. This interface has only one method:
IlvActivity createActivity(IlvTimeInterval interval)
In the Gantt chart and Schedule chart examples, whenever you create a new activity using the mouse, the interactor asks the chart factory to create the actual IlvActivity object by calling this method. (For information on interactors, see Interacting with the Gantt charts.) By default, the chart activity factory is an instance of IlvGeneralActivity.Factory.
You can use the following IlvHierarchyChart methods to change this:
*IlvActivityFactory getActivityFactory()
*void setActivityFactory(IlvActivityFactory factory)
In this manner, the decision as to what type of activity to create is dissociated from the interactor, which only determines when the activity should be created based upon mouse events.
The activity factory can also be used to remove the hard-coded dependency on a specific IlvActivity implementation from your own code. For example, instead of writing:
IlvActivity rootActivity = new IlvGeneralActivity(...);
as in the previous section, you could write the following code:
IlvActivityFactory activityFactory = myChart.getActivityFactory();
IlvActivity rootActivity = activityFactory.createActivity(...);
NOTE The class IlvGeneralActivity.Factory creates each new activity with a default name and identifier of “New Activity”, located in resource files for easier localization. You will probably want to modify these default attributes before adding the new activity to your data model.
The Gantt chart and Schedule chart examples use this technique to populate the data model.
NOTE The Resource Data chart does not support interactive creation of data model objects. Therefore, it does not contain any API for data model factories.
In addition to an activity factory, the class IlvScheduleChart also inherits a resource factory from the class IlvHierarchyChart. This factory is defined by the IlvResourceFactory interface. Like the activity factory, this interface has only one method:
IlvResource createResource()
By default, the chart resource factory is an instance of IlvGeneralResource.Factory.
However, you can use the following IlvHierarchyChart methods to change this:
*IlvResourceFactory getResourceFactory()
*void setResourceFactory(IlvResourceFactory factory)
You can use the resource factory to create resource objects for your data model:
IlvResourceFactory resourceFactory = myChart.getResourceFactory();
IlvResource rootResource = resourceFactory.createResource();
NOTE The IlvGeneralResource.Factory class creates each new resource with a default name and identifier of “New Resource”, located in resource files for easier localization. You will probably want to modify these default attributes before adding the new resource to your data model.
Constraints
You can create a constraint between two activities. (See Constraints in Introducing JViews Gantt.) A constraint is defined by the IlvConstraint interface. It also has a type, defined by the IlvConstraintType class whose four static constants define the supported constraint types:
*IlvConstraintType.START_START
*IlvConstraintType.START_END
*IlvConstraintType.END_START
*IlvConstraintType.END_END
The following figure shows the associations between the classes needed to model constraints.
Prerequisites to adding a constraint
The IlvConstraintType class has a private constructor, so that no other instances can be created. Think of this feature as the Java™ equivalent of a C++ enumerated type. Before you can add a constraint to the Gantt data model, the two activities involved must already be members of the data model. For example:
IlvGanttModel ganttModel = new IlvDefaultGanttModel();
IlvActivity rootActivity = new IlvGeneralActivity(...);
ganttModel.setRootActivity(rootActivity);
IlvActivity child1 = new IlvGeneralActivity(...);
ganttModel.addActivity(child1, rootActivity);
IlvActivity child2 = new IlvGeneralActivity(...);
ganttModel.addActivity(child2 rootActivity);
// Create a constraint between child1 and child2
IlvConstraint constraint =
    new IlvGeneralConstraint(child1, child2, IlvConstraintType.END_START);
ganttModel.addConstraint(constraint);
If either of the constrained activities is removed from the data model, the constraint will also be removed. This avoids “loose” constraints and maintains the invariant whereby a constraint always links two activities in the same Gantt data model.
The following IlvGanttModel methods allow you to manipulate the constraints within the data model:
*void addConstraint(IlvConstraint newConstraint)
*void removeConstraint(IlvConstraint constraint)
*Iterator constraintIterator()
*Iterator constraintIteratorFromActivity(IlvActivity fromActivity)
*Iterator constraintIteratorToActivity(IlvActivity toActivity)
The constraint factory
As with activities and resources, the IlvHierarchyChart class also contains a constraint factory, defined by the IlvConstraintFactory interface. Like activity and resource factories, this interface has only one method:
IlvConstraint createConstraint(IlvActivity from,
                               IlvActivity to,
                               IlvConstraintType type)
By default, the chart constraint factory is an instance of the IlvGeneralConstraint.Factory class.
However, you can use the following methods of the class IlvHierarchyChart to change this:
*IlvConstraintFactory getConstraintFactory()
*void setConstraintFactory(IlvConstraintFactory factory)
You can use the constraint factory to create constraint objects for your data model:
IlvConstraintFactory constraintFactory = myChart.getConstraintFactory();
IlvConstraint constraint = 
     constraintFactory.createConstraint
          (activity1, activity2, IlvConstraintType.END_START);
Reservations
A reservation is created between a resource and an activity. Another way to think of this is that the activity has “reserved” the resource for its execution. A reservation is defined by the IlvReservation interface.
The following figure shows the associations between the classes needed to model reservations.
Prerequisite to adding a reservation
Before you can add a reservation to the Gantt data model, both the resource and the activity must already be members of the data model. For example:
IlvGanttModel ganttModel = new IlvDefaultGanttModel();
IlvActivity rootActivity = new IlvGeneralActivity(...);
ganttModel.setRootActivity(rootActivity);
IlvActivity childActivity = new IlvGeneralActivity(...);
ganttModel.addActivity(childActivity, rootActivity);
IlvResource rootResource = new IlvGeneralResource(...);
ganttModel.setRootResource(rootResource);
IlvResource childResource = new IlvGeneralResource(...);
ganttModel.addResource(childResource, rootResource);
// Create a reservation between childActivity and childResource
IlvReservation r = new IlvGeneralReservation(childResource, childActivity);
ganttModel.addReservation(r);
If either the activity or the resource is removed from the data model, the reservation will also be removed. This avoids “loose” reservations and maintains the invariant whereby a reservation always links an activity to a resource in the same Gantt data model.
The following IlvGanttModel methods allow you to manipulate the reservations within the data model:
*void addReservation(IlvReservation newReservation)
*void removeReservation(IlvReservation reservation)
*Iterator reservationIterator()
*Iterator reservationIterator(IlvActivity activity)
*Iterator reservationIterator(IlvResource resource)
*Iterator reservationIterator(IlvResource resource, IlvTimeInterval interval)
The reservation factory
As in Activity and resource factories and The constraint factory, the IlvHierarchyChart class also contains a reservation factory, defined by the IlvReservationFactory interface. As with the other equivalent interfaces, this interface has only one method:
IlvReservation createReservation(IlvResource resource, IlvActivity activity)
By default, the chart reservation factory is an instance of the IlvGeneralReservation.Factory class.
However, you can use the following methods of the IlvHierarchyChart class to change this:
*IlvReservationFactory getReservationFactory()
*void setReservationFactory(IlvReservationFactory factory)
You can use the reservation factory to create reservation objects for your data model:
IlvReservationFactory reservationFactory = myChart.getReservationFactory();
IlvReservation reservation =
     reservationFactory.createReservation(aResource, anActivity);

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