18 |
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.action;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.action.CreateFrameAbstractAction;
|
|
|
17 |
import org.openconcerto.erp.config.ComptaPropsConfiguration;
|
|
|
18 |
import org.openconcerto.erp.core.common.ui.DeviseNiceTableCellRenderer;
|
|
|
19 |
import org.openconcerto.erp.core.sales.product.ui.FamilleArticlePanel;
|
|
|
20 |
import org.openconcerto.erp.panel.ITreeSelection;
|
|
|
21 |
import org.openconcerto.sql.Configuration;
|
|
|
22 |
import org.openconcerto.sql.element.SQLElement;
|
|
|
23 |
import org.openconcerto.sql.model.SQLRow;
|
|
|
24 |
import org.openconcerto.sql.model.SQLTable;
|
|
|
25 |
import org.openconcerto.sql.model.Where;
|
|
|
26 |
import org.openconcerto.sql.request.ListSQLRequest;
|
|
|
27 |
import org.openconcerto.sql.view.ListeAddPanel;
|
|
|
28 |
import org.openconcerto.sql.view.list.IListe;
|
|
|
29 |
import org.openconcerto.ui.DefaultGridBagConstraints;
|
|
|
30 |
import org.openconcerto.ui.PanelFrame;
|
|
|
31 |
|
|
|
32 |
import java.awt.GridBagConstraints;
|
|
|
33 |
import java.awt.GridBagLayout;
|
|
|
34 |
import java.awt.Insets;
|
|
|
35 |
import java.awt.event.ActionEvent;
|
|
|
36 |
import java.awt.event.ActionListener;
|
|
|
37 |
import java.beans.PropertyChangeEvent;
|
|
|
38 |
import java.beans.PropertyChangeListener;
|
|
|
39 |
import java.math.BigInteger;
|
|
|
40 |
|
|
|
41 |
import javax.swing.Action;
|
|
|
42 |
import javax.swing.JFrame;
|
|
|
43 |
import javax.swing.JPanel;
|
|
|
44 |
import javax.swing.JSplitPane;
|
|
|
45 |
import javax.swing.JTable;
|
|
|
46 |
import javax.swing.event.TableModelEvent;
|
|
|
47 |
import javax.swing.event.TableModelListener;
|
|
|
48 |
|
|
|
49 |
public class ListeDesArticlesAction extends CreateFrameAbstractAction {
|
|
|
50 |
|
|
|
51 |
private PanelFrame panelFrame;
|
|
|
52 |
String title = "Liste des articles";
|
|
|
53 |
private final SQLTable sqlTableArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("ARTICLE");
|
|
|
54 |
private final SQLTable sqlTableFamilleArticle = ((ComptaPropsConfiguration) Configuration.getInstance()).getRootSociete().getTable("FAMILLE_ARTICLE");
|
|
|
55 |
|
|
|
56 |
public ListeDesArticlesAction() {
|
|
|
57 |
super();
|
|
|
58 |
this.putValue(Action.NAME, "Liste des articles");
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public JFrame createFrame() {
|
|
|
62 |
final FamilleArticlePanel panelFam = new FamilleArticlePanel();
|
|
|
63 |
|
|
|
64 |
// Renderer pour les devises
|
|
|
65 |
// frame.getPanel().getListe().getJTable().setDefaultRenderer(Long.class, new
|
|
|
66 |
// DeviseNiceTableCellRenderer());
|
|
|
67 |
SQLElement elt = Configuration.getInstance().getDirectory().getElement(this.sqlTableArticle);
|
|
|
68 |
IListe liste = new IListe(ListSQLRequest.copy(elt.getListRequest(), getWhere(panelFam)));
|
|
|
69 |
final ListeAddPanel panel = new ListeAddPanel(elt, liste);
|
|
|
70 |
|
|
|
71 |
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panelFam, panel);
|
|
|
72 |
JPanel panelAll = new JPanel(new GridBagLayout());
|
|
|
73 |
GridBagConstraints c = new DefaultGridBagConstraints();
|
|
|
74 |
c.fill = GridBagConstraints.BOTH;
|
|
|
75 |
c.weightx = 1;
|
|
|
76 |
c.weighty = 1;
|
|
|
77 |
c.insets = new Insets(0, 0, 0, 0);
|
|
|
78 |
panelAll.add(pane, c);
|
|
|
79 |
|
|
|
80 |
DeviseNiceTableCellRenderer rend = new DeviseNiceTableCellRenderer();
|
|
|
81 |
JTable table = panel.getListe().getJTable();
|
|
|
82 |
for (int i = 0; i < table.getColumnCount(); i++) {
|
|
|
83 |
if (table.getColumnClass(i) == Long.class || table.getColumnClass(i) == BigInteger.class) {
|
|
|
84 |
table.getColumnModel().getColumn(i).setCellRenderer(rend);
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
final ITreeSelection tree = panelFam.getFamilleTree();
|
|
|
89 |
tree.addValueListener(new PropertyChangeListener() {
|
|
|
90 |
@Override
|
|
|
91 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
92 |
|
|
|
93 |
panel.getListe().getRequest().setWhere(getWhere(panelFam));
|
|
|
94 |
|
|
|
95 |
}
|
|
|
96 |
});
|
|
|
97 |
|
|
|
98 |
// rafraichir le titre à chaque changement de la liste
|
|
|
99 |
panel.getListe().addListener(new TableModelListener() {
|
|
|
100 |
public void tableChanged(TableModelEvent e) {
|
|
|
101 |
setTitle(panel);
|
|
|
102 |
}
|
|
|
103 |
});
|
|
|
104 |
panel.getListe().addListenerOnModel(new PropertyChangeListener() {
|
|
|
105 |
@Override
|
|
|
106 |
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
107 |
if (evt.getPropertyName() == null || evt.getPropertyName().equals("loading") || evt.getPropertyName().equals("searching"))
|
|
|
108 |
setTitle(panel);
|
|
|
109 |
}
|
|
|
110 |
});
|
|
|
111 |
|
|
|
112 |
panelFam.getCheckObsolete().addActionListener(new ActionListener() {
|
|
|
113 |
@Override
|
|
|
114 |
public void actionPerformed(ActionEvent e) {
|
|
|
115 |
|
|
|
116 |
panel.getListe().getRequest().setWhere(getWhere(panelFam));
|
|
|
117 |
}
|
|
|
118 |
});
|
|
|
119 |
|
|
|
120 |
this.panelFrame = new PanelFrame(panelAll, "Liste des articles");
|
|
|
121 |
return this.panelFrame;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
protected void setTitle(ListeAddPanel panel) {
|
|
|
125 |
String title = this.title;
|
|
|
126 |
if (panel.getListe().getModel().isLoading())
|
|
|
127 |
title += ", chargement en cours";
|
|
|
128 |
if (panel.getListe().getModel().isSearching())
|
|
|
129 |
title += ", recherche en cours";
|
|
|
130 |
|
|
|
131 |
this.panelFrame.setTitle(title);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
/**
|
|
|
135 |
* Filtre par rapport à la famille sélectionnée
|
|
|
136 |
*
|
|
|
137 |
* @param panel
|
|
|
138 |
* @return le where approprié
|
|
|
139 |
*/
|
|
|
140 |
public Where getWhere(FamilleArticlePanel panel) {
|
|
|
141 |
int id = panel.getFamilleTree().getSelectedID();
|
|
|
142 |
|
|
|
143 |
Where w = null;
|
|
|
144 |
|
|
|
145 |
if (panel.getCheckObsolete().isSelected()) {
|
|
|
146 |
w = new Where(this.sqlTableArticle.getField("OBSOLETE"), "=", Boolean.FALSE);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
if (id > 1) {
|
|
|
150 |
SQLRow row = this.sqlTableFamilleArticle.getRow(id);
|
|
|
151 |
String code = row.getString("CODE") + "%";
|
|
|
152 |
Where w2 = new Where(this.sqlTableArticle.getField("ID_FAMILLE_ARTICLE"), "=", this.sqlTableFamilleArticle.getKey());
|
|
|
153 |
if (w != null) {
|
|
|
154 |
w = w.and(w2);
|
|
|
155 |
} else {
|
|
|
156 |
w = w2;
|
|
|
157 |
}
|
|
|
158 |
w = w.and(new Where(this.sqlTableFamilleArticle.getField("CODE"), "LIKE", code));
|
|
|
159 |
}
|
|
|
160 |
return w;
|
|
|
161 |
}
|
|
|
162 |
}
|