Bug #1570: Fix issue updating the EV chart legend instead of creating it from scratch

When the date in the legend was modified, all the checkboxes were removed and
created from scratch. Now it is set an id for the labels associated to each
textbox and its value is updated accordingly when changing the date instead of
create them again.

FEA: ItEr77S04BugFixing
This commit is contained in:
Manuel Rego Casasnovas 2012-11-23 10:06:51 +01:00
parent 14e2cc4209
commit 4cc12a3dbf
2 changed files with 52 additions and 25 deletions

View file

@ -345,15 +345,21 @@ public class CompanyPlanningModel implements ICompanyPlanningModel {
LocalDate date = new LocalDate(datebox.getValue());
org.zkoss.zk.ui.Component child = vbox
.getFellow("indicatorsTable");
vbox.removeChild(child);
vbox.appendChild(getEarnedValueChartConfigurableLegend(
earnedValueChartFiller, date));
updateEarnedValueChartLegend(vbox, earnedValueChartFiller, date);
dateInfutureMessage(datebox);
}
});
}
private void updateEarnedValueChartLegend(Vbox vbox,
CompanyEarnedValueChartFiller earnedValueChartFiller, LocalDate date) {
for (EarnedValueType type : EarnedValueType.values()) {
Label valueLabel = (Label) vbox.getFellow(type.toString());
valueLabel.setValue(getLabelTextEarnedValueType(earnedValueChartFiller, type, date));
}
}
private void dateInfutureMessage(Datebox datebox) {
Date value = datebox.getValue();
Date today = LocalDate.fromDateFields(new Date())
@ -466,16 +472,9 @@ public class CompanyPlanningModel implements ICompanyPlanningModel {
checkbox.setAttribute("indicator", type);
checkbox.setStyle("color: " + type.getColor());
BigDecimal value = earnedValueChartFiller.getIndicator(type, date) != null ? earnedValueChartFiller
.getIndicator(type, date)
: BigDecimal.ZERO;
String units = _("h");
if (type.equals(EarnedValueType.CPI)
|| type.equals(EarnedValueType.SPI)) {
value = value.multiply(new BigDecimal(100));
units = "%";
}
Label valueLabel = new Label(value.intValue() + " " + units);
Label valueLabel = new Label(getLabelTextEarnedValueType(
earnedValueChartFiller, type, date));
valueLabel.setId(type.toString());
Hbox hbox = new Hbox();
hbox.appendChild(checkbox);
@ -506,6 +505,20 @@ public class CompanyPlanningModel implements ICompanyPlanningModel {
return mainhbox;
}
private String getLabelTextEarnedValueType(
CompanyEarnedValueChartFiller earnedValueChartFiller,
EarnedValueType type, LocalDate date) {
BigDecimal value = earnedValueChartFiller.getIndicator(type, date) != null ? earnedValueChartFiller
.getIndicator(type, date) : BigDecimal.ZERO;
String units = _("h");
if (type.equals(EarnedValueType.CPI)
|| type.equals(EarnedValueType.SPI)) {
value = value.multiply(new BigDecimal(100));
units = "%";
}
return value.intValue() + " " + units;
}
private void markAsSelectedDefaultIndicators() {
for (Checkbox checkbox : earnedValueChartConfigurationCheckboxes) {
EarnedValueType type = (EarnedValueType) checkbox

View file

@ -805,9 +805,16 @@ public class OrderPlanningModel implements IOrderPlanningModel {
LocalDate date = new LocalDate(earnedValueChartLegendDatebox.getRawValue());
org.zkoss.zk.ui.Component child = earnedValueChartLegendContainer
.getFellow("indicatorsTable");
earnedValueChartLegendContainer.removeChild(child);
earnedValueChartLegendContainer.appendChild(getEarnedValueChartConfigurableLegend(
earnedValueChartFiller, date));
updateEarnedValueChartLegend(date);
}
private void updateEarnedValueChartLegend(LocalDate date) {
for (EarnedValueType type : EarnedValueType.values()) {
Label valueLabel = (Label) earnedValueChartLegendContainer
.getFellow(type.toString());
valueLabel.setValue(getLabelTextEarnedValueType(
earnedValueChartFiller, type, date));
}
}
private org.zkoss.zk.ui.Component getEarnedValueChartConfigurableLegend(
@ -832,15 +839,9 @@ public class OrderPlanningModel implements IOrderPlanningModel {
checkbox.setAttribute("indicator", type);
checkbox.setStyle("color: " + type.getColor());
BigDecimal value = earnedValueChartFiller.getIndicator(type, date);
String units = _("h");
if (type.equals(EarnedValueType.CPI)
|| type.equals(EarnedValueType.SPI)) {
value = value.multiply(new BigDecimal(100));
units = "%";
}
Label valueLabel = new Label(
value.setScale(0, RoundingMode.HALF_UP) + " " + units);
Label valueLabel = new Label(getLabelTextEarnedValueType(
earnedValueChartFiller, type, date));
valueLabel.setId(type.toString());
Hbox hbox = new Hbox();
hbox.appendChild(checkbox);
@ -871,6 +872,19 @@ public class OrderPlanningModel implements IOrderPlanningModel {
return mainhbox;
}
private String getLabelTextEarnedValueType(
OrderEarnedValueChartFiller earnedValueChartFiller,
EarnedValueType type, LocalDate date) {
BigDecimal value = earnedValueChartFiller.getIndicator(type, date);
String units = _("h");
if (type.equals(EarnedValueType.CPI)
|| type.equals(EarnedValueType.SPI)) {
value = value.multiply(new BigDecimal(100));
units = "%";
}
return value.setScale(0, RoundingMode.HALF_UP) + " " + units;
}
private void markAsSelectedDefaultIndicators() {
for (Checkbox checkbox : earnedValueChartConfigurationCheckboxes) {
EarnedValueType type = (EarnedValueType) checkbox