Show progress on general task depending on type of progress selected on configuration menu

* Added listbox with list of progress types; now it should refresh the progress of each
task whenever a new type of progress is selected

FEA: ItEr64OTS04ReporteAvancesCadeaCritica
This commit is contained in:
Diego Pino Garcia 2010-11-23 19:14:44 +01:00
parent 3aad0de4a6
commit 3b85ac0dd9
15 changed files with 251 additions and 39 deletions

View file

@ -708,4 +708,8 @@ public class Planner extends HtmlMacroComponent {
return context.getCriticalPath();
}
public void updateCompletion(String progressType) {
getTaskList().updateCompletion(progressType);
}
}

View file

@ -36,8 +36,8 @@ import org.zkoss.ganttz.adapters.IDisabilityConfiguration;
import org.zkoss.ganttz.data.GanttDate;
import org.zkoss.ganttz.data.Milestone;
import org.zkoss.ganttz.data.Task;
import org.zkoss.ganttz.data.TaskContainer;
import org.zkoss.ganttz.data.Task.IReloadResourcesTextRequested;
import org.zkoss.ganttz.data.TaskContainer;
import org.zkoss.ganttz.data.constraint.Constraint;
import org.zkoss.ganttz.data.constraint.Constraint.IConstraintViolationListener;
import org.zkoss.lang.Objects;
@ -500,6 +500,15 @@ public class TaskComponent extends Div implements AfterCompose {
widthAdvancePercentage));
}
public void updateCompletion(String progressType) {
int startPixels = this.task.getBeginDate().toPixels(getMapper());
String widthAdvancePercentage = pixelsFromStartUntil(startPixels,
this.task.getAdvanceEndDate(progressType)) + "px";
response(null, new AuInvoke(this, "resizeCompletion2Advance",
widthAdvancePercentage));
}
private int pixelsFromStartUntil(int startPixels, GanttDate until) {
int endPixels = until.toPixels(getMapper());
assert endPixels >= startPixels;
@ -510,6 +519,10 @@ public class TaskComponent extends Div implements AfterCompose {
smartUpdate("taskTooltipText", task.updateTooltipText());
}
public void updateTooltipText(String progressType) {
smartUpdate("taskTooltipText", task.updateTooltipText(progressType));
}
private DependencyList getDependencyList() {
return getGanntPanel().getDependencyList();
}

View file

@ -93,6 +93,13 @@ public class TaskList extends XulElement implements AfterCompose {
this.predicate = predicate;
}
public void updateCompletion(String progressType) {
for (TaskComponent task: getTaskComponents()) {
task.updateCompletion(progressType);
task.updateTooltipText(progressType);
}
}
public List<Task> getAllTasks() {
return new ArrayList<Task>(currentTotalTasks);
}

View file

@ -246,4 +246,14 @@ public class DefaultFundamentalProperties implements ITaskFundamentalProperties
return Collections.emptyList();
}
@Override
public GanttDate getAdvanceEndDate(String progressType) {
return null;
}
@Override
public String updateTooltipText(String progressType) {
return "";
}
}

View file

@ -98,4 +98,8 @@ public interface ITaskFundamentalProperties {
public List<Constraint<GanttDate>> getCurrentLengthConstraint();
public GanttDate getAdvanceEndDate(String progressType);
String updateTooltipText(String progressType);
}

View file

@ -289,6 +289,10 @@ public abstract class Task implements ITaskFundamentalProperties {
return fundamentalProperties.getAdvanceEndDate();
}
public GanttDate getAdvanceEndDate(String progressType) {
return fundamentalProperties.getAdvanceEndDate(progressType);
}
public String getTooltipText() {
return fundamentalProperties.getTooltipText();
}
@ -297,6 +301,10 @@ public abstract class Task implements ITaskFundamentalProperties {
return fundamentalProperties.updateTooltipText();
}
public String updateTooltipText(String progressType) {
return fundamentalProperties.updateTooltipText(progressType);
}
public String getLabelsText() {
return fundamentalProperties.getLabelsText();
}

View file

@ -46,6 +46,12 @@ planner = self;
model="${planner.zoomLevels}"
onSelect="planner.setZoomLevel(self.selectedItem.value);" >
</listbox>
<!-- Progress type -->
<label>${i18n:_('Progress')}:</label>
<listbox id="lbProgressTypes"
mold="select" />
<button id="showCriticalPath" onClick="planner.showCriticalPath();"
image="/common/img/ico_criticalpath.png"
tooltiptext="${i18n:_('Show/Hide Critical path')}" />
@ -94,4 +100,4 @@ planner = self;
id="graphics" onOpen="planner.changeChartVisibility(event.open);" height="200px">
<div id="insertionPointChart" />
</south>
</borderlayout>
</borderlayout>

View file

@ -54,4 +54,13 @@ public enum ProgressType {
return Arrays.asList(ProgressType.values());
}
public static ProgressType asEnum(String value) {
for (ProgressType each: getAll()) {
if (each.getValue().equals(value)) {
return each;
}
}
return null;
}
}

View file

@ -41,6 +41,7 @@ import org.hibernate.validator.NotNull;
import org.joda.time.LocalDate;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.common.BaseEntity;
import org.navalplanner.business.common.entities.ProgressType;
import org.navalplanner.business.orders.entities.OrderElement;
import org.navalplanner.business.orders.entities.TaskSource;
import org.navalplanner.business.planner.entities.Dependency.Type;
@ -601,6 +602,13 @@ public abstract class TaskElement extends BaseEntity {
: advancePercentage;
}
public BigDecimal getAdvancePercentage(ProgressType progressType) {
if (progressType.equals(ProgressType.NORMAL)) {
return advancePercentage;
}
return BigDecimal.ZERO;
}
public void setAdvancePercentage(BigDecimal advancePercentage) {
this.advancePercentage = advancePercentage;
}

View file

@ -32,6 +32,9 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.AssertTrue;
import org.navalplanner.business.common.Registry;
import org.navalplanner.business.common.daos.IConfigurationDAO;
import org.navalplanner.business.common.entities.ProgressType;
import org.navalplanner.business.orders.entities.TaskSource;
import org.navalplanner.business.scenarios.entities.Scenario;
import org.navalplanner.business.workingday.IntraDayDate;
@ -49,6 +52,8 @@ public class TaskGroup extends TaskElement {
private List<TaskElement> taskElements = new ArrayList<TaskElement>();
private IConfigurationDAO configurationDAO;
/**
* Constructor for hibernate. Do not use!
*/
@ -240,4 +245,37 @@ public class TaskGroup extends TaskElement {
criticalPathProgress.update(criticalPath);
}
@Override
public BigDecimal getAdvancePercentage() {
return getAdvancePercentage(getConfigurationDAO().getConfiguration()
.getProgressType());
}
private IConfigurationDAO getConfigurationDAO() {
if (configurationDAO == null) {
configurationDAO = Registry.getConfigurationDAO();
}
return configurationDAO;
}
public BigDecimal getAdvancePercentage(ProgressType progressType) {
if (isTaskRoot(this)) {
if (progressType.equals(ProgressType.CRITICAL_PATH_DURATION)) {
return getCriticalPathProgressByDuration();
}
if (progressType.equals(ProgressType.CRITICAL_PATH_NUMHOURS)) {
return getCriticalPathProgressByNumHours();
}
}
return super.getAdvancePercentage();
}
private boolean isTaskRoot(TaskGroup taskGroup) {
return taskGroup.getParent() == null;
}
public BigDecimal getRawAdvancePercentage() {
return super.getAdvancePercentage();
}
}

View file

@ -53,6 +53,7 @@ import org.joda.time.Seconds;
import org.navalplanner.business.calendars.entities.BaseCalendar;
import org.navalplanner.business.common.IAdHocTransactionService;
import org.navalplanner.business.common.IOnTransaction;
import org.navalplanner.business.common.entities.ProgressType;
import org.navalplanner.business.labels.entities.Label;
import org.navalplanner.business.orders.daos.IOrderElementDAO;
import org.navalplanner.business.orders.entities.OrderElement;
@ -300,6 +301,7 @@ public class TaskElementAdapter implements ITaskElementAdapter {
private class TaskElementWrapper implements ITaskFundamentalProperties {
private final TaskElement taskElement;
private final Scenario currentScenario;
protected TaskElementWrapper(Scenario currentScenario,
@ -450,33 +452,46 @@ public class TaskElementAdapter implements ITaskElementAdapter {
}
@Override
public GanttDate getAdvanceEndDate() {
OrderElement orderElement = taskElement.getOrderElement();
public GanttDate getAdvanceEndDate(String progressType) {
return getAdvanceEndDate(ProgressType.asEnum(progressType));
}
BigDecimal advancePercentage;
Integer hours;
if (orderElement != null) {
advancePercentage = taskElement.getAdvancePercentage();
private GanttDate getAdvanceEndDate(ProgressType progressType) {
BigDecimal advancePercentage = BigDecimal.ZERO;
if (taskElement.getOrderElement() != null) {
advancePercentage = taskElement
.getAdvancePercentage(progressType);
}
return getAdvanceEndDate(advancePercentage);
}
@Override
public GanttDate getAdvanceEndDate() {
BigDecimal advancePercentage = BigDecimal.ZERO;
if (taskElement.getOrderElement() != null) {
advancePercentage = taskElement
.getAdvancePercentage();
}
return getAdvanceEndDate(advancePercentage);
}
private GanttDate getAdvanceEndDate(BigDecimal advancePercentage) {
Integer hours = Integer.valueOf(0);
if (taskElement.getOrderElement() != null) {
hours = taskElement.getSumOfHoursAllocated();
} else {
advancePercentage = new BigDecimal(0);
hours = Integer.valueOf(0);
}
Integer advanceHours = advancePercentage.multiply(
new BigDecimal(hours)).intValue();
if (taskElement instanceof TaskGroup) {
return calculateLimitDate(advancePercentage);
}
GanttDate result;
if(taskElement instanceof TaskGroup) {
// Calculate date according to advanceHours or advancePercentage
final Integer advanceHours = advancePercentage.multiply(
new BigDecimal(hours)).intValue();
GanttDate result = calculateLimitDate(advanceHours);
if (result == null) {
result = calculateLimitDate(advancePercentage);
}
else {
result = calculateLimitDate(advanceHours);
if (result == null) {
result = calculateLimitDate(advancePercentage);
}
}
return result;
}
@ -526,14 +541,6 @@ public class TaskElementAdapter implements ITaskElementAdapter {
return toGantt(end);
}
@Override
public BigDecimal getAdvancePercentage() {
if (taskElement != null) {
return taskElement.getAdvancePercentage();
}
return new BigDecimal(0);
}
private GanttDate calculateLimitDate(Integer hours) {
if (hours == null || hours == 0) {
return null;
@ -633,8 +640,6 @@ public class TaskElementAdapter implements ITaskElementAdapter {
}
}
private Set<Label> getLabelsFromElementAndPredecesors(
OrderElement order) {
if (order != null) {
@ -718,13 +723,32 @@ public class TaskElementAdapter implements ITaskElementAdapter {
return buildTooltipText();
}
@Override
public String updateTooltipText(String progressType) {
return buildTooltipText(ProgressType.asEnum(progressType));
}
@Override
public BigDecimal getAdvancePercentage() {
if (taskElement != null) {
return taskElement.getAdvancePercentage();
}
return new BigDecimal(0);
}
private String buildTooltipText() {
return buildTooltipText(asPercentage(taskElement.getAdvancePercentage()));
}
private BigDecimal asPercentage(BigDecimal value) {
return value.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.DOWN);
}
private String buildTooltipText(BigDecimal progressPercentage) {
StringBuilder result = new StringBuilder();
result.append(_("Name: {0}", getName()) + "<br/>");
result.append(_("Advance") + ": ").append(
(getAdvancePercentage().multiply(new BigDecimal(100)))
.setScale(2, RoundingMode.DOWN))
.append("% , ");
result.append(_("Advance") + ": ")
.append(progressPercentage).append("% , ");
result.append(_("Hours invested") + ": ").append(
getHoursAdvancePercentage().multiply(new BigDecimal(100)))
@ -738,6 +762,10 @@ public class TaskElementAdapter implements ITaskElementAdapter {
return result.toString();
}
private String buildTooltipText(ProgressType progressType) {
return buildTooltipText(asPercentage(taskElement.getAdvancePercentage(progressType)));
}
private String getOrderState() {
String cssClass;
OrderStatusEnum state = taskElement.getOrderElement().getOrder().getState();

View file

@ -29,6 +29,7 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang.Validate;
import org.navalplanner.business.common.entities.ProgressType;
import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.web.common.components.bandboxsearch.BandboxMultipleSearch;
import org.navalplanner.web.common.components.finders.FilterPair;
@ -47,10 +48,16 @@ import org.zkoss.ganttz.util.script.IScriptsRegister;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Composer;
import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Constraint;
import org.zkoss.zul.Datebox;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.Vbox;
/**
@ -61,7 +68,7 @@ import org.zkoss.zul.Vbox;
*/
@org.springframework.stereotype.Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class CompanyPlanningController implements Composer{
public class CompanyPlanningController implements Composer {
@Autowired
private ICompanyPlanningModel model;
@ -91,6 +98,8 @@ public class CompanyPlanningController implements Composer{
.retrieve();
}
private Listbox lbProgressTypes;
@Override
public void doAfterCompose(org.zkoss.zk.ui.Component comp) {
planner = (Planner) comp;
@ -106,6 +115,8 @@ public class CompanyPlanningController implements Composer{
planner.setAreContainersExpandedByDefault(Planner
.guessContainersExpandedByDefault(parameters));
initializeListboxProgressTypes();
orderFilter = (Vbox) planner.getFellow("orderFilter");
// Configuration of the order filter
Component filterComponent = Executions.createComponents(
@ -123,6 +134,49 @@ public class CompanyPlanningController implements Composer{
filterComponent.setVisible(true);
}
private void initializeListboxProgressTypes() {
if (lbProgressTypes == null) {
lbProgressTypes = (Listbox) planner.getFellow("lbProgressTypes");
}
lbProgressTypes.setModel(new SimpleListModel(ProgressType.getAll()));
// Select default configuration option
lbProgressTypes.renderAll();
Listitem item = findListitemValue(lbProgressTypes, getProgressTypeFromConfiguration());
if (item != null) {
lbProgressTypes.setSelectedItem(item);
}
// Update completion of tasks on selecting new progress type
lbProgressTypes.addEventListener(Events.ON_SELECT, new EventListener() {
@Override
public void onEvent(Event event) throws Exception {
ProgressType progressType = getSelectedProgressType();
planner.updateCompletion(progressType.toString());
}
private ProgressType getSelectedProgressType() {
return (ProgressType) lbProgressTypes.getSelectedItem().getValue();
}
});
}
private Listitem findListitemValue(Listbox listbox, ProgressType value) {
for (Object each : listbox.getChildren()) {
final Listitem item = (Listitem) each;
if (value.equals(item.getValue())) {
return item;
}
}
return null;
}
public ProgressType getProgressTypeFromConfiguration() {
return model.getProgressTypeFromConfiguration();
}
public void setConfigurationForPlanner() {
// Added predicate
model

View file

@ -42,6 +42,7 @@ import org.joda.time.LocalDate;
import org.navalplanner.business.common.IAdHocTransactionService;
import org.navalplanner.business.common.IOnTransaction;
import org.navalplanner.business.common.daos.IConfigurationDAO;
import org.navalplanner.business.common.entities.ProgressType;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.hibernate.notification.PredefinedDatabaseSnapshots;
import org.navalplanner.business.orders.daos.IOrderDAO;
@ -920,4 +921,10 @@ public abstract class CompanyPlanningModel implements ICompanyPlanningModel {
public void goToCreateOtherOrderFromTemplate(OrderTemplate template) {
tabs.goToCreateotherOrderFromTemplate(template);
}
@Transactional(readOnly=true)
public ProgressType getProgressTypeFromConfiguration() {
return configurationDAO.getConfiguration().getProgressType();
}
}

View file

@ -23,6 +23,7 @@ package org.navalplanner.web.planner.company;
import java.util.Collection;
import org.joda.time.LocalDate;
import org.navalplanner.business.common.entities.ProgressType;
import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.business.templates.entities.OrderTemplate;
import org.navalplanner.web.planner.tabs.MultipleTabsPlannerController;
@ -55,4 +56,7 @@ public interface ICompanyPlanningModel {
LocalDate getFilterFinishDate();
void goToCreateOtherOrderFromTemplate(OrderTemplate template);
ProgressType getProgressTypeFromConfiguration();
}

View file

@ -533,10 +533,21 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
final Tabpanel tabpanel = getSelectedPanel(selectedTab);
overallProgressContent = new OverAllProgressContent(tabpanel);
}
overallProgressContent.update();
updateOverAllProgressContent();
}
}
private void updateOverAllProgressContent() {
transactionService
.runOnTransaction(new IOnTransaction<Void>() {
@Override
public Void execute() {
overallProgressContent.update();
return null;
}
});
}
private boolean isOverAllProgressSelected(Tab selectedTab) {
return selectedTab != null
&& selectedTab.getLabel().equals(_("Overall progress"));
@ -1570,10 +1581,11 @@ public abstract class OrderPlanningModel implements IOrderPlanningModel {
lbAdvancePercentage = (Label) tabpanel.getFellowIfAny("lbAdvancePercentage");
}
@Transactional(readOnly=true)
public void update() {
TaskGroup rootTask = planningState.getRootTask();
setAdvancePercentage(rootTask.getAdvancePercentage());
setAdvancePercentage(rootTask.getRawAdvancePercentage());
setCriticalPathByDuration(rootTask.getCriticalPathProgressByDuration());
setCriticalPathByNumHours(rootTask.getCriticalPathProgressByNumHours());
}