185 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011-2019 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.supplychain.stock.element;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.preferences.GestionArticleGlobalPreferencePanel;
|
|
|
17 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
18 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
19 |
import org.openconcerto.sql.preferences.SQLPreferences;
|
|
|
20 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
21 |
import org.openconcerto.ui.table.JTreeTable;
|
|
|
22 |
import org.openconcerto.ui.table.MultiLineHeaderRenderer;
|
|
|
23 |
|
|
|
24 |
import java.awt.Component;
|
|
|
25 |
import java.awt.Dimension;
|
|
|
26 |
import java.awt.GridBagConstraints;
|
|
|
27 |
import java.awt.GridBagLayout;
|
|
|
28 |
import java.awt.event.ActionEvent;
|
|
|
29 |
import java.awt.event.ActionListener;
|
|
|
30 |
import java.text.SimpleDateFormat;
|
|
|
31 |
import java.util.Date;
|
|
|
32 |
import java.util.Enumeration;
|
|
|
33 |
|
|
|
34 |
import javax.swing.JButton;
|
|
|
35 |
import javax.swing.JFrame;
|
|
|
36 |
import javax.swing.JLabel;
|
|
|
37 |
import javax.swing.JPanel;
|
|
|
38 |
import javax.swing.JScrollPane;
|
|
|
39 |
import javax.swing.JTable;
|
|
|
40 |
import javax.swing.SwingConstants;
|
|
|
41 |
import javax.swing.SwingUtilities;
|
|
|
42 |
import javax.swing.table.DefaultTableCellRenderer;
|
|
|
43 |
import javax.swing.table.TableColumn;
|
|
|
44 |
|
|
|
45 |
public class StockConsultPanel extends JPanel {
|
|
|
46 |
|
|
|
47 |
private JTable tableStock;
|
|
|
48 |
private StockTreeModel stockModel;
|
|
|
49 |
private JLabel code = new JLabel();
|
|
|
50 |
private JLabel nom = new JLabel();
|
|
|
51 |
private JLabel taille = new JLabel();
|
|
|
52 |
private JLabel couleur = new JLabel();
|
|
|
53 |
private final boolean hasDeclinaison;
|
|
|
54 |
|
|
|
55 |
public StockConsultPanel(SQLElement eltArt, SQLRowAccessor sqlRowAccessor) {
|
|
|
56 |
super(new GridBagLayout());
|
|
|
57 |
final SQLPreferences prefs = SQLPreferences.getMemCached(eltArt.getTable().getDBRoot());
|
|
|
58 |
this.hasDeclinaison = prefs.getBoolean(GestionArticleGlobalPreferencePanel.ACTIVER_DECLINAISON, false);
|
|
|
59 |
|
|
|
60 |
final GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
61 |
c.fill = GridBagConstraints.HORIZONTAL;
|
|
|
62 |
c.gridx = 0;
|
|
|
63 |
c.weightx = 0;
|
|
|
64 |
this.add(new JLabel("Code : ", SwingConstants.RIGHT), c);
|
|
|
65 |
c.gridx++;
|
|
|
66 |
c.weightx = 1;
|
|
|
67 |
this.add(this.code, c);
|
|
|
68 |
c.gridy++;
|
|
|
69 |
c.gridx = 0;
|
|
|
70 |
c.weightx = 0;
|
|
|
71 |
this.add(new JLabel("Désignation : ", SwingConstants.RIGHT), c);
|
|
|
72 |
c.weightx = 0;
|
|
|
73 |
c.gridx++;
|
|
|
74 |
c.weightx = 1;
|
|
|
75 |
this.add(this.nom, c);
|
|
|
76 |
|
|
|
77 |
if (this.hasDeclinaison) {
|
|
|
78 |
// Taille
|
|
|
79 |
c.gridy++;
|
|
|
80 |
c.gridx = 0;
|
|
|
81 |
c.weightx = 0;
|
|
|
82 |
this.add(new JLabel("Taille : ", SwingConstants.RIGHT), c);
|
|
|
83 |
c.weightx = 0;
|
|
|
84 |
c.gridx++;
|
|
|
85 |
c.weightx = 1;
|
|
|
86 |
this.add(this.taille, c);
|
|
|
87 |
// Couleur
|
|
|
88 |
c.gridy++;
|
|
|
89 |
c.gridx = 0;
|
|
|
90 |
c.weightx = 0;
|
|
|
91 |
this.add(new JLabel("Couleur : ", SwingConstants.RIGHT), c);
|
|
|
92 |
c.gridx++;
|
|
|
93 |
c.weightx = 0;
|
|
|
94 |
c.weightx = 1;
|
|
|
95 |
this.add(this.couleur, c);
|
|
|
96 |
}
|
|
|
97 |
c.gridy++;
|
|
|
98 |
c.gridx = 0;
|
|
|
99 |
c.fill = GridBagConstraints.BOTH;
|
|
|
100 |
c.gridwidth = 2;
|
|
|
101 |
c.weighty = 1;
|
|
|
102 |
this.stockModel = new StockTreeModel(new StockRootNode(eltArt.getForeignElement("ID_STOCK")));
|
|
|
103 |
load(sqlRowAccessor);
|
|
|
104 |
this.tableStock = new JTreeTable(this.stockModel);
|
|
|
105 |
|
|
|
106 |
MultiLineHeaderRenderer renderer = new MultiLineHeaderRenderer();
|
|
|
107 |
Enumeration e = this.tableStock.getColumnModel().getColumns();
|
|
|
108 |
while (e.hasMoreElements()) {
|
|
|
109 |
final TableColumn tableColumn = (TableColumn) e.nextElement();
|
|
|
110 |
tableColumn.setHeaderRenderer(renderer);
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
this.tableStock.getColumnModel().getColumn(0).setWidth(260);
|
|
|
114 |
this.tableStock.getColumnModel().getColumn(0).setMinWidth(200);
|
|
|
115 |
if (this.tableStock.getColumnModel().getColumnCount() > 5) {
|
|
|
116 |
this.tableStock.getColumnModel().getColumn(5).setCellRenderer(new DefaultTableCellRenderer() {
|
|
|
117 |
@Override
|
|
|
118 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
119 |
if (value != null) {
|
|
|
120 |
value = new SimpleDateFormat("dd/MM/yyyy").format((Date) value);
|
|
|
121 |
}
|
|
|
122 |
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
|
123 |
}
|
|
|
124 |
});
|
|
|
125 |
}
|
|
|
126 |
this.add(new JScrollPane(this.tableStock), c);
|
|
|
127 |
c.fill = GridBagConstraints.NONE;
|
|
|
128 |
c.anchor = GridBagConstraints.SOUTHEAST;
|
|
|
129 |
final JButton close = new JButton("Fermer");
|
|
|
130 |
close.addActionListener(new ActionListener() {
|
|
|
131 |
|
|
|
132 |
@Override
|
|
|
133 |
public void actionPerformed(ActionEvent e) {
|
|
|
134 |
((JFrame) SwingUtilities.getRoot(StockConsultPanel.this)).dispose();
|
|
|
135 |
}
|
|
|
136 |
});
|
|
|
137 |
this.add(close, c);
|
|
|
138 |
this.setMinimumSize(new Dimension(960, 400));
|
|
|
139 |
this.setPreferredSize(new Dimension(960, 400));
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
public void load(SQLRowAccessor article) {
|
|
|
143 |
this.code.setText(article.getString("CODE"));
|
|
|
144 |
this.nom.setText(article.getString("NOM"));
|
|
|
145 |
if (this.hasDeclinaison) {
|
|
|
146 |
final SQLRowAccessor nonEmptyForeignTaille = article.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_TAILLE");
|
|
|
147 |
if (nonEmptyForeignTaille != null) {
|
|
|
148 |
this.taille.setText(nonEmptyForeignTaille.getString("NOM"));
|
|
|
149 |
} else {
|
|
|
150 |
this.taille.setText("");
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
final SQLRowAccessor nonEmptyForeignCouleur = article.getNonEmptyForeign("ID_ARTICLE_DECLINAISON_COULEUR");
|
|
|
154 |
if (nonEmptyForeignCouleur != null) {
|
|
|
155 |
this.couleur.setText(nonEmptyForeignCouleur.getString("NOM"));
|
|
|
156 |
} else {
|
|
|
157 |
this.couleur.setText("");
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
}
|
|
|
161 |
this.stockModel.load(article);
|
|
|
162 |
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
}
|