Multiple Entries

For many scheduling projects it is very useful to display multiple entries onto a single row, the usage of this
is typically for the work-scheduling where the resource appears on the left hand-side and the resources allocation is measured on the right in the form of tasks:
multi-entry.jpg

In the example shown above we randomly generate the colours of the entires and create the entry with the GanttDrawingPartHelper class.

The usage of this class is more complex than the GanttEntryHelper the basic operation is:
  • helper.createDrawingState - Create the holder for the parts
  • helper.createDrawingPart - Create the holder for the entries
  • helper.createActivityEntry - Create the Entries one by one and add them to the part
  • drawingState.addPart - Add the part back to the state

The code behind each row is the following:

private DrawingState createDrawingState(int start, int finish, int segments) {
 
BasicDrawingState state = GanttDrawingPartHelper.createDrawingState();
int offset;
{
int range = finish - start;
offset = range / Math.max(segments, 1);
}
 
Random random = new Random();
ListDrawingPart part = GanttDrawingPartHelper.createDrawingPart();
for (int i=start; i < finish; i+=offset ) {
 
String context = "";
 
switch (random.nextInt(3)) {
case 0 : context = GradientColorModule.BLUE_GRADIENT_CONTEXT; break;
case 1 : context = GradientColorModule.RED_GRADIENT_CONTEXT; break;
case 2 : context = GradientColorModule.PINK_GRADIENT_CONTEXT; break;
default:
context = GradientColorModule.GREEN_GRADIENT_CONTEXT;
}
 
GanttDrawingPartHelper.createActivityEntry(new Object(), new Date(i), new Date(i + offset), context, part);
}
state.addDrawingPart(part);
return state;
}

The same technique can be used for adding text labels to appear ontop of the entries. In which case you would create two DrawingParts one for the DrawingLayer and the other for the TextLayer.

see example below:
private DrawingState createDrawingState(int start, int finish, int segments) {
 
BasicDrawingState state = GanttDrawingPartHelper.createDrawingState();
int offset;
{
int range = finish - start;
offset = range / Math.max(segments, 1);
}
 
Random random = new Random();
ListDrawingPart drawingLayer = GanttDrawingPartHelper.createDrawingPart();
ListDrawingPart textLayer = GanttDrawingPartHelper.createDrawingPart();
for (int i=start; i < finish; i+=offset ) {
 
String context = "";
String localizedText = "";
 
switch (random.nextInt(3)) {
case 0 :
context = GradientColorModule.BLUE_GRADIENT_CONTEXT;
localizedText = "Blue";
break;
case 1 : context = GradientColorModule.RED_GRADIENT_CONTEXT;
localizedText = "Red";
break;
case 2 : context = GradientColorModule.PINK_GRADIENT_CONTEXT;
localizedText = "Pink";
break;
default:
context = GradientColorModule.GREEN_GRADIENT_CONTEXT;
localizedText = "Green";
break;
}
 
final Object o = new Object();
 
GanttDrawingPartHelper.createActivityEntry(o, new Date(i), new Date(i + offset), context, drawingLayer);
GanttDrawingPartHelper.createActivityEntry(new StringBuffer(localizedText), new Date(i), new Date(i + offset), BasicPainterModule.BASIC_STRING_PAINTER, TEXT_PAINTER, textLayer);
}
 
state.addDrawingPart(drawingLayer);
state.addDrawingPart(textLayer);
return state;
}
external image sflogo.php?group_id=49356