forked from LupusNobilis/java-org.hwo.ui
86 lines
1.9 KiB
Java
86 lines
1.9 KiB
Java
|
package org.hwo.ui.gantt;
|
||
|
|
||
|
import org.hwo.datetime.DateTime;
|
||
|
|
||
|
public class BaseGanttResource implements IGanttResource {
|
||
|
|
||
|
private String shortLabel;
|
||
|
private String detailedLabel;
|
||
|
private int maxParallelUsage;
|
||
|
|
||
|
private ResourceAvailability resourceAvailability;
|
||
|
|
||
|
public BaseGanttResource(String shortLabel,String detailedLabel) {
|
||
|
this.shortLabel = shortLabel;
|
||
|
this.detailedLabel = detailedLabel;
|
||
|
this.maxParallelUsage = 1;
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public String getLabel() {
|
||
|
return this.shortLabel;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getDetailedLabel() {
|
||
|
return this.detailedLabel;
|
||
|
}
|
||
|
|
||
|
|
||
|
public void setResourceAvailability(
|
||
|
ResourceAvailability resourceAvailability) {
|
||
|
this.resourceAvailability = resourceAvailability;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ResourceAvailability getAvailability() {
|
||
|
return resourceAvailability;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public ResourceAvailability getAvailability(DateTime fromDateTime) {
|
||
|
return resourceAvailability.findAvailableAfter(fromDateTime);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getMaxParallelUsage() {
|
||
|
return this.maxParallelUsage;
|
||
|
}
|
||
|
|
||
|
public void setMaxParallelUsage(int maxParallelUsage) {
|
||
|
this.maxParallelUsage = maxParallelUsage;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
public DateTime calculateUsageTime(DateTime begin,int seconds){
|
||
|
ResourceAvailability ra = getAvailability(begin);
|
||
|
DateTime dt = new DateTime(begin);
|
||
|
|
||
|
if (ra != null && dt.isBefore(ra.getStartTime())){
|
||
|
dt = ra.getStartTime();
|
||
|
}
|
||
|
|
||
|
while (ra != null){
|
||
|
int availSeconds = ra.getSeconds(dt);
|
||
|
|
||
|
//System.err.println(String.format("RES: %s needs %d seconds from %s. Has %d seconds.", shortLabel, seconds, dt.toString(), availSeconds));
|
||
|
|
||
|
if (availSeconds >= seconds){ // Soll kann erfüllt werden...
|
||
|
DateTime endTime = new DateTime(dt);
|
||
|
endTime.addSeconds(seconds);
|
||
|
return endTime;
|
||
|
}
|
||
|
|
||
|
seconds -= availSeconds;
|
||
|
|
||
|
ra = ra.getNext();
|
||
|
dt = ra.getStartTime();
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|