});
}
@SuppressWarnings({ "rawtypes", "unchecked" })
private void createDeductionGrid() {
final NumberFormat numberFormat = NumberFormat.getFormat(NUMBER_FORMAT);
final String[] headers = { "<br><br>" + messages.del(), "<br><br>" + messages.date(),
messages.canto() + "<br>" + numberFormat.format(ratioList[0]), messages.badge() + "<br>" + numberFormat.format(ratioList[1]),
messages.grue() + "<br>" + numberFormat.format(ratioList[2]), messages.lift() + "<br>" + numberFormat.format(ratioList[3]),
messages.benne() + "<br>" + numberFormat.format(ratioList[4]), messages.nettoyage() + "<br>" + numberFormat.format(ratioList[5]),
messages.autres() + "<br>-", messages.prorata() + "<br>" + numberFormat.format(ratioList[6]), "<br><br>" + messages.refacturations() };
bus.addHandler(PrestationEvent.TYPE, new PrestationHandler() {
@Override
public void onChangePrestation(PrestationEvent prestationEvent) {
switch (prestationEvent.getIndex()) {
case 0: // messages.canto()
ratioList[0] = prestationEvent.getValue();
deductionGrid.getColumnModel().setColumnHeader(2, messages.canto() + "<br>" + numberFormat.format(ratioList[0]));
deductionGrid.getView().refresh(true);
break;
case 1: // messages.badge()
ratioList[1] = prestationEvent.getValue();
deductionGrid.getColumnModel().setColumnHeader(3, messages.badge() + "<br>" + numberFormat.format(ratioList[1]));
deductionGrid.getView().refresh(true);
break;
case 2: // messages.grue()
ratioList[2] = prestationEvent.getValue();
deductionGrid.getColumnModel().setColumnHeader(4, messages.grue() + "<br>" + numberFormat.format(ratioList[2]));
deductionGrid.getView().refresh(true);
break;
case 3: // messages.lift()
ratioList[3] = prestationEvent.getValue();
deductionGrid.getColumnModel().setColumnHeader(5, messages.lift() + "<br>" + numberFormat.format(ratioList[3]));
deductionGrid.getView().refresh(true);
break;
case 4: // messages.benne()
ratioList[4] = prestationEvent.getValue();
deductionGrid.getColumnModel().setColumnHeader(6, messages.benne() + "<br>" + numberFormat.format(ratioList[4]));
deductionGrid.getView().refresh(true);
break;
case 5: // messages.nettoyage()
ratioList[5] = prestationEvent.getValue();
deductionGrid.getColumnModel().setColumnHeader(7, messages.nettoyage() + "<br>" + numberFormat.format(ratioList[5]));
deductionGrid.getView().refresh(true);
break;
case 6: // messages.prorata()
ratioList[6] = prestationEvent.getValue();
deductionGrid.getColumnModel().setColumnHeader(9, messages.prorata() + "<br>" + numberFormat.format(ratioList[6]));
deductionGrid.getView().refresh(true);
break;
}
}
});
if (ratioList[0] == 1 && ratioList[1] == 1 && ratioList[2] == 1 && ratioList[3] == 1 && ratioList[4] == 1 && ratioList[5] == 1
&& ratioList[6] == 1) {
Map<Integer, String> mapPrestations = navigation.getContext().getMapPrestations();
String prestationValue = mapPrestations.get(ficheStId);
if (prestationValue != null && prestationValue.length() > 0) {
String arrRatio[] = prestationValue.split(Constants.SEPRATE);
ratioList[0] = new Double(arrRatio[0]);
ratioList[1] = new Double(arrRatio[1]);
ratioList[2] = new Double(arrRatio[2]);
ratioList[3] = new Double(arrRatio[3]);
ratioList[4] = new Double(arrRatio[4]);
ratioList[5] = new Double(arrRatio[5]);
ratioList[6] = new Double(arrRatio[6]);
headers[2] = messages.canto() + "<br>" + numberFormat.format(ratioList[0]);
headers[3] = messages.badge() + "<br>" + numberFormat.format(ratioList[1]);
headers[4] = messages.grue() + "<br>" + numberFormat.format(ratioList[2]);
headers[5] = messages.lift() + "<br>" + numberFormat.format(ratioList[3]);
headers[6] = messages.benne() + "<br>" + numberFormat.format(ratioList[4]);
headers[7] = messages.nettoyage() + "<br>" + numberFormat.format(ratioList[5]);
headers[9] = messages.prorata() + "<br>" + numberFormat.format(ratioList[6]);
}
}
final String[] ids = { DeductionDto.ID, DeductionDto.DATE, DeductionDto.CANTO, DeductionDto.BADGE, DeductionDto.GRUE, DeductionDto.LIFT,
DeductionDto.BENNE, DeductionDto.NETTOYAGE, DeductionDto.AUTRES, DeductionDto.PRORATA, DeductionDto.REFACTURATIONS };
int commonWidth = 112;
int[] columnsWidth = { DELETE_BUTTON_WIDTH, commonWidth + 20, commonWidth, commonWidth, commonWidth, commonWidth, commonWidth, commonWidth,
commonWidth, commonWidth, commonWidth };
HorizontalAlignment[] horizontalAlignments = { HorizontalAlignment.CENTER };
AggregationRowConfig<DeductionDto> totalSummary = new AggregationRowConfig<DeductionDto>();
totalSummary.setHtml(DeductionDto.DATE, messages.total());
// For Report
totaldeduction = "";
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
for (int i = 0; i < ids.length; i++) {
String columnId = ids[i];
SummaryColumnConfig column = new SummaryColumnConfig(columnId, headers[i], columnsWidth[i]);
column.setAlignment(horizontalAlignments[0]);
column.setMenuDisabled(true);
columns.add(column);
if (i == 0) {
column.setRenderer(createDeleteButtonRenderer());
} else if (i == 1) {
column.setRenderer(createDateRendererWithPermision(column.getWidth() - PADDING_2, role, user));
// column.setEditor(new CellEditor(createDateField()));
} else if (i <= 7) {
column.setRenderer(createIntegerRendererWithPermission(commonWidth - PADDING, role, user));
NumberField numberField = createIntegerField(null);
numberField.setPropertyEditorType(Integer.class);
column.setEditor(new CellEditor(numberField));
} else {
column.setRenderer(createNumberRendererWithPermission(commonWidth - PADDING, role, user));
NumberField numberField = createNumberField(null);
if (i == 9) {
numberField.setMinValue(0);
numberField.setMaxValue(100);
column.setEditor(new CellEditor(numberField));
}
}
if (i > 1 && i != 9 && i != 10) {
// Total summary columns
totalSummary.setSummaryFormat(columnId, NumberFormat.getFormat(NUMBER_FORMAT));
totalSummary.setSummaryType(columnId, new SummaryType<Double>() {
@Override
public Double render(Object v, ModelData m, String field, Map<String, Object> data) {
if (v == null) {
v = 0.0;
}
Object obj = m.get(field);
if (obj != null) {
double ratio = findRatio(field);
totaldeduction += numberFormat.format(((Double) v) + ((Number) obj).doubleValue() * ratio) + Constants.SEPRATE;
return ((Double) v) + ((Number) obj).doubleValue() * ratio;
}
totaldeduction += numberFormat.format(((Double) v)) + Constants.SEPRATE;
return ((Double) v);
}
private double findRatio(String field) {
for (int i = 0; i <= ids.length; i++) {
String columnId = ids[i];
if (columnId.equalsIgnoreCase(field)) {
if (DeductionDto.AUTRES.equalsIgnoreCase(field)) {
return 1.0;
} else {
return ratioList[i - 2];
}
}
}
return 0.0;
}
});
}
if (i == 9) {
// Total summary columns
totalSummary.setSummaryFormat(columnId, NumberFormat.getFormat(NUMBER_FORMAT));
totalSummary.setSummaryType(columnId, new SummaryType<Double>() {
@Override
public Double render(Object v, ModelData m, String field, Map<String, Object> data) {
if (v == null) {
v = 0.0;
}
Object obj = m.get(field);
if (obj != null) {
totaldeduction += numberFormat.format(((Double) v) + ((Number) obj).doubleValue()) + Constants.SEPRATE;
return ((Double) v) + ((Number) obj).doubleValue() * ratioList[6];
}
totaldeduction += numberFormat.format(((Double) v)) + Constants.SEPRATE;
return ((Double) v);
}
});
}
if (i == 10) {
// Total summary columns
totalSummary.setSummaryFormat(columnId, NumberFormat.getFormat(NUMBER_FORMAT));
totalSummary.setSummaryType(columnId, new SummaryType<Double>() {
@Override
public Double render(Object v, ModelData m, String field, Map<String, Object> data) {
if (v == null) {
v = 0.0;
}
Object obj = m.get(field);
if (obj != null) {
totaldeduction += numberFormat.format(((Double) v) + ((Number) obj).doubleValue()) + Constants.SEPRATE;
return ((Double) v) + ((Number) obj).doubleValue();
}
totaldeduction += numberFormat.format(((Double) v)) + Constants.SEPRATE;
return ((Double) v);
}
});
}
}