OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 142 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
142 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.common.ui.DeviseNiceTableCellRenderer;
17
import org.openconcerto.sql.model.SQLRowValues;
18
import org.openconcerto.sql.view.list.RowValuesTable;
19
import org.openconcerto.sql.view.list.RowValuesTableModel;
20
import org.openconcerto.ui.table.AlternateTableCellRenderer;
21
import org.openconcerto.utils.CollectionUtils;
22
 
23
import java.awt.Color;
24
import java.awt.Component;
25
 
26
import javax.swing.JLabel;
27
import javax.swing.JTable;
28
import javax.swing.SwingConstants;
29
 
30
public class DeliveredQtyRowValuesRenderer extends DeviseNiceTableCellRenderer {
31
 
32
    // Red
33
    public static final Color red = new Color(255, 31, 52);
34
    public static final Color redLightGrey = new Color(240, 65, 85);
35
 
36
    // Orange
37
    public final static Color orange = new Color(243, 125, 75);
38
    public final static Color orangeGrey = new Color(222, 107, 47);
39
 
40
    // Blue
41
    public final static Color light = new Color(232, 238, 250);
42
    public final static Color lightGrey = new Color(211, 220, 222);
43
 
44
    // Black
45
    public final static Color lightBlack = new Color(192, 192, 192);
46
    public final static Color lightBlackGrey = new Color(155, 155, 155);
47
 
174 ilm 48
    private final boolean customer;
49
 
142 ilm 50
    public DeliveredQtyRowValuesRenderer() {
174 ilm 51
        this(true);
52
    }
53
 
54
    public DeliveredQtyRowValuesRenderer(boolean customer) {
142 ilm 55
        AlternateTableCellRenderer.setBGColorMap(this, CollectionUtils.createMap(lightBlack, lightBlackGrey, red, redLightGrey, orange, orangeGrey));
174 ilm 56
        this.customer = customer;
142 ilm 57
    }
58
 
59
    @Override
60
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
61
 
62
        Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
63
 
64
        if (table instanceof RowValuesTable) {
65
 
66
            ((JLabel) comp).setHorizontalAlignment(SwingConstants.RIGHT);
67
            RowValuesTableModel model = ((RowValuesTable) table).getRowValuesTableModel();
68
            SQLRowValues rowVals = model.getRowValuesAt(row);
69
 
174 ilm 70
            Number qte;
71
            Number qteL;
72
            if (this.customer) {
73
                qte = (Number) rowVals.getObject("QTE");
74
                qteL = (Number) rowVals.getObject("QTE_LIVREE");
75
            } else {
76
                qte = (Number) rowVals.getObject("QTE_ORIGINE");
77
                qteL = (Number) rowVals.getObject("QTE");
78
            }
142 ilm 79
            if (qte != null && qteL != null) {
80
                if (qte.intValue() < qteL.intValue()) {
81
                    comp.setBackground(red);
82
                } else if (qteL.intValue() <= 0) {
83
                    comp.setBackground(lightBlack);
84
                } else if (qteL.intValue() != qte.intValue()) {
85
                    comp.setBackground(orange);
86
                }
87
            }
88
        }
89
        return comp;
90
    }
91
}