93 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.sales.product.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.finance.accounting.model.CurrencyConverter;
|
|
|
17 |
import org.openconcerto.sql.model.FieldPath;
|
|
|
18 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
19 |
import org.openconcerto.sql.model.graph.Step;
|
|
|
20 |
import org.openconcerto.sql.view.list.RowValuesTable;
|
|
|
21 |
import org.openconcerto.sql.view.list.RowValuesTableModel;
|
|
|
22 |
import org.openconcerto.utils.GestionDevise;
|
|
|
23 |
|
|
|
24 |
import java.awt.Component;
|
|
|
25 |
import java.math.BigDecimal;
|
|
|
26 |
import java.util.List;
|
|
|
27 |
|
|
|
28 |
import javax.swing.JTable;
|
|
|
29 |
import javax.swing.SwingConstants;
|
|
|
30 |
import javax.swing.table.DefaultTableCellRenderer;
|
|
|
31 |
|
|
|
32 |
public class CurrencyWithSymbolRenderer extends DefaultTableCellRenderer {
|
|
|
33 |
|
|
|
34 |
private final FieldPath fieldPath;
|
|
|
35 |
private final CurrencyConverter c;
|
|
|
36 |
|
|
|
37 |
private String getSymbol(String currencyCode) {
|
|
|
38 |
// Because Java Currency return PLN as Symbol for Zl, we use our own talbe
|
|
|
39 |
return org.openconcerto.erp.core.finance.accounting.model.Currency.getSymbol(currencyCode);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Affiche une valeur monétaire en ajoutant le symbole de la devise de la société
|
|
|
44 |
*/
|
|
|
45 |
public CurrencyWithSymbolRenderer() {
|
|
|
46 |
this(null);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Affiche une valeur monétaire en ajoutant le symbole de la devise du path
|
|
|
51 |
*
|
|
|
52 |
* @param path chemin jusqu'au champ DEVISE.CODE
|
|
|
53 |
*/
|
|
|
54 |
public CurrencyWithSymbolRenderer(FieldPath path) {
|
|
|
55 |
this.fieldPath = path;
|
|
|
56 |
this.c = new CurrencyConverter();
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
@Override
|
|
|
60 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
61 |
|
|
|
62 |
if (value != null) {
|
|
|
63 |
value = GestionDevise.currencyToString((BigDecimal) value);
|
|
|
64 |
|
|
|
65 |
if (fieldPath == null) {
|
|
|
66 |
value = value + " " + getSymbol(c.getCompanyCurrencyCode());
|
|
|
67 |
} else {
|
|
|
68 |
|
|
|
69 |
if (table instanceof RowValuesTable) {
|
|
|
70 |
|
|
|
71 |
RowValuesTableModel model = ((RowValuesTable) table).getRowValuesTableModel();
|
|
|
72 |
|
|
|
73 |
SQLRowAccessor rowVals = model.getRowValuesAt(row);
|
|
|
74 |
|
|
|
75 |
// final SQLRow asRow = rowVals.asRow();
|
|
|
76 |
// SQLRow deviseRow = asRow;
|
|
|
77 |
// Ne pas utiliser getDistant row --> fait une requete dans la base et ne
|
|
|
78 |
// reprend
|
|
|
79 |
// pas les valeurs de la SQLRow (ex : si on veut récupérer la devise du
|
|
|
80 |
// fournisseur
|
|
|
81 |
// sélectionné, getDistantRow ira chercher la valeur du fournisseur référencé en
|
|
|
82 |
// BDD
|
|
|
83 |
// et non dans la SQLRow)
|
|
|
84 |
|
|
|
85 |
final List<Step> steps = this.fieldPath.getPath().getSteps();
|
|
|
86 |
for (int i = 0; i < steps.size(); i++) {
|
|
|
87 |
final Step s = steps.get(i);
|
|
|
88 |
// On s'assure que la row existe
|
|
|
89 |
if (rowVals != null && !rowVals.isUndefined()) {
|
|
|
90 |
// On s'assure que la row contient le champ
|
|
|
91 |
if (!rowVals.getFields().contains(s.getSingleField().getName())) {
|
|
|
92 |
rowVals = null;
|
|
|
93 |
break;
|
|
|
94 |
}
|
|
|
95 |
final SQLRowAccessor foreign = rowVals.getForeign(s.getSingleField().getName());
|
132 |
ilm |
96 |
if (i == 0 && foreign != null) {
|
93 |
ilm |
97 |
rowVals = foreign.asRow();
|
|
|
98 |
} else {
|
|
|
99 |
rowVals = foreign;
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
if (rowVals != null && !rowVals.isUndefined()) {
|
|
|
105 |
String code = rowVals.getString(this.fieldPath.getFieldName());
|
|
|
106 |
value = value + " " + getSymbol(code);
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
112 |
|
|
|
113 |
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
|
114 |
}
|
|
|
115 |
}
|